Elasticsearch-dsl-py: Unable to create custom filter

Created on 13 Jul 2018  路  2Comments  路  Source: elastic/elasticsearch-dsl-py

I am using phonetic plugin for elasticsearch. My setting configuration is:

"settings": {
    "index": {
      "analysis": {
        "filter": {
          "dbl_metaphone": {
            "type": "phonetic",
            "encoder": "double_metaphone"
          }
        }
      }
      "analyzer": {
        "dbl_metaphone": {
          "tokenizer": "standard",
          "filter": "dbl_metaphone"
        }
      }
    }
  }

I tried to implement it using elasticsearch-dsl(version-6.1.0)

from elasticsearch_dsl.analysis import TokenFilter
from elasticsearch-dsl import DocType, Text, analyzer, tokenizer, token_filter
class PhoneticFilter(TokenFilter):
    name = 'phonetic_filter'
    encoder = 'double_metaphone'
    type = 'phonetic'
phonetic = PhoneticFilter()
dbl_metaphone = analyzer('dbl_metaphone',
                         tokenizer='standard',
                         filter=[token_filter(phonetic)])
class UserIndex(DocType):
    name = Text(analyzer='standard',
         fields={'phonetic': Text(analyzer=dbl_metaphone)}
    )
    class Meta:
        index='my-index'

When I run UserIndex.init(), it shows the following error:

TransportError: TransportError(500, 'settings_exception', 'Failed to load settings from [{"analysis":{"analyzer":{"dbl_metaphone":{"filter":[{"phonetic_filter":{}}],"type":"custom","tokenizer":"standard"}}}}]')

How can I fix it?

PS: I have user this reference

All 2 comments

No answers? Give some suggestions atleast... @HonzaKral

To implement this just follow the described API:

from elasticsearch_dsl.analysis import analyzer, token_filter
ph = token_filter('dbl_metaphone', 'phonetic', encoder='double_metaphone')
dbl_metaphone = analyzer('dbl_metaphone', tokenizer='standard', filter=[ph])

now you can use dbl_metaphone as analyzer in your Text field.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

rokcarl picture rokcarl  路  4Comments

vmogilev picture vmogilev  路  4Comments

MauriJHN picture MauriJHN  路  4Comments

takaomag picture takaomag  路  3Comments

barseghyanartur picture barseghyanartur  路  4Comments