使用python调用_analyze进行Elasticsearch 6.x

时间:2018-12-18 07:14:15

标签: python-3.x elasticsearch

如何执行

的调用
DesiredCapabilities

在python弹性搜索6.x API中?

我尝试过

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

它给出了异常

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

2 个答案:

答案 0 :(得分:2)

尝试一下:

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__':
    from elasticsearch import client
    es = get_es()
    indexES = client.IndicesClient(es)
    body={
      "analyzer": "german_analyzer",
      "text": "kann"
    }
    result = indexES.analyze(index="faq-kbaid-de-index", body=body)
    i=1

答案 1 :(得分:0)

es.search()调用_search。您可以通过elasticsearch.client.IndicesClient呼叫_analyze。将.search行替换为

result = es.indices.analyze(index="faq-kbaid-de-index", body=body,
                           size=1)