How to use "suggest" in elasticsearch pyes?

How to use the offer function in pyes? It may not seem that this is due to poor documentation. Can someone provide a working example? Nothing I tried seems to work. In the documents listed in the request, but using:

query = Suggest(fields="fieldname") connectionobject.search(query=query) 
+6
source share
2 answers

Here is my code that works great.

 from elasticsearch import Elasticsearch es = Elasticsearch() text = 'ra' suggDoc = { "entity-suggest" : { 'text' : text, "completion" : { "field" : "suggest" } } } res = es.suggest(body=suggDoc, index="auto_sugg", params=None) print(res) 

I used the same client mentioned on elasticsearch here
i indexed data in an elasticsearch index using completion suggester from here

+3
source

Starting with version 5:

End point

_suggest is deprecated in favor of using a sentence through the _search endpoint. In 5.0, the _search endpoint has been optimized to offer only search queries.

(from https://www.elastic.co/guide/en/elasticsearch/reference/5.5/search-suggesters.html )

The best way to do this is to use api to search with the suggest option

 from elasticsearch import Elasticsearch es = Elasticsearch() text = 'ra' suggest_dictionary = {"my-entity-suggest" : { 'text' : text, "completion" : { "field" : "suggest" } } } query_dictionary = {'suggest' : suggest_dictionary} res = es.search( index='auto_sugg', doc_type='entity', body=query_dictionary) print(res) 

Make sure you include each document with the suggest field suggest

 sample_entity= { 'id' : 'test123', 'name': 'Ramtin Seraj', 'title' : 'XYZ', "suggest" : { "input": [ 'Ramtin', 'Seraj', 'XYZ'], "output": "Ramtin Seraj", "weight" : 34 # a prior weight } } 
+2
source

Source: https://habr.com/ru/post/971844/


All Articles