簡體   English   中英

如何在彈性搜索中使用“建議”?

[英]How to use “suggest” in elasticsearch pyes?

如何在pyes中使用“建議”功能? 由於文檔很差,似乎無法弄明白。 有人能提供一個有效的例子嗎? 我試過的一切似乎都沒有用。 在其查詢下列出的文檔中,但使用:

query = Suggest(fields="fieldname")
connectionobject.search(query=query)

從第5版開始:

_suggest端點已被棄用,轉而使用通過_search端點建議。 在5.0中,_search端點已經過優化,僅用於建議搜索請求。

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

更好的方法是使用帶有suggest選項的搜索API

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)

確保已使用suggest字段為每個文檔編制索引

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

這是我的代碼完美運行。

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)

我在這里使用了elasticsearch網站上提到的相同客戶端
我使用completion suggester這里索引彈性搜索索引中的數據

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM