Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

calling _analyze with python for elasticsearch 6.x

How to perform the calling of

POST my_index/_analyze
{
  "analyzer": "german_analyzer",
  "text": "kann"
}

in python elastic search 6.x api?

I tried

def get_es():

    # Variables for Elasticsearch host+port
    es_host = 'localhost'
    es_port = 9200

    from elasticsearch import Elasticsearch
    es = Elasticsearch([{'host': es_host, 'port': es_port}])
    return es

if __name__ == '__main__':

    es = get_es()
    body={
      "analyzer": "german_analyzer",
      "text": "kann"
    }
    result = es.search(index="faq-kbaid-de-index", body=body,
                               size=1)
    i=1

it gives exception

elasticsearch.exceptions.RequestError: RequestError(400, 'parsing_exception', 'Unknown key for a VALUE_STRING in [analyzer].')
like image 729
william007 Avatar asked Oct 19 '25 14:10

william007


1 Answers

es.search() calles _search. You can call _analyze via elasticsearch.client.IndicesClient. Replace the .search line with

result = es.indices.analyze(index="faq-kbaid-de-index", body=body,
                           size=1)
like image 105
dtrv Avatar answered Oct 22 '25 03:10

dtrv



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!