Search code examples
pythonelasticsearchelasticsearch-dslelasticsearch-pyelasticsearch-dsl-py

Any suggestions to customize an analyzer when using query match with elasticsearch-py?


I can't apply a custom analyzer when using query match with elasticsearch-py.

I customized an analyzer called custom_lowercase_stemmed and used es.indices.put_settings to update the index setting.

However, it couldn't find the analyzer when I do a search.

I also looked into the parameter analyzer in es.search, but it returns an error:

..unrecognized parameter: [analyzer]

Can I get any suggestions here in terms of a customized analyzer? Thank you!

query_body = {
     "query": {
         "match": {
            "employer":{
                "query": txt,
                "fuzziness": 'AUTO',
                "analyzer" : 'custom_lowercase_stemmed'
            }
        }
    }
}
es.search(index='hello',body=query_body)

Here is the full error:

RequestError: RequestError(400, 'search_phase_execution_exception', '[match] analyzer [custom_lowercase_stemmed] not found')

Solution

  • I think you have to make sure you have the following:

    • Have your Configuration set properly. In your case, you should have in your settings the field "custom_lowercase_stemmed" as analyzer. You can also define the words you want to stop.

    • With the Python ES Client, you have to send the analyzer as a parameter of the method .search(). Check the docs. However, you can try to run your query as it is. I haven't played that much with analyzer.

    Hope this is helpful! :D