简体   繁体   中英

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')

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

Ensure that you have specified your analyzer at your mapping and ensure your querying the correct field as well.

For your question on the matching problem for removing duplicate names, at term level and short words, fuzziness and wildcard parameters would be the best fit!

Cheers, Min Han (:

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM