[英]Elastic Search boost query corresponding to first search term
我正在使用PyElasticsearch
( PyElasticsearch
python客戶端庫)。 我正在搜索像Arvind Kejriwal India Today經濟時報這樣的字符串,這給了我合理的結果。 我希望我能在搜索查詢中增加第一個單詞的權重。 我怎樣才能做到這一點?
res = es.search(index="article-index", fields="url", body={
"query": {
"query_string": {
"query": "keywordstr",
"fields": [
"text",
"title",
"tags",
"domain"
]
}
}
})
我正在使用上面的命令來搜索。
將給定查詢拆分為多個術語。 在您的示例中,它將是Arvind,Kejriwal ...現在為每個給定的術語形成查詢字符串查詢(或字段查詢或任何其他適合需要的內容)。 查詢字符串查詢將如下所示http://www.elasticsearch.org/guide/en/elasticsearch/reference/0.90/query-dsl-query-string-query.html
{
"query_string" : {
"default_field" : "content",
"query" : "<one of the given term>",
"boost": <any number>
}
}
現在你有多個像上面這樣的查詢具有不同的提升值(取決於具有更高權重的查詢)。 使用BOOL查詢將所有這些查詢合並到一個查詢中。 http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/query-dsl-bool-query.html如果您希望結果中包含所有術語,則查詢將如下所示。
{
"bool" : {
"must" : [q1, q2, q3 ...]
}
}
你可以使用bool查詢的不同選項。 例如,您希望在結果中顯示3個術語中的任何一個,那么查詢就像
{
"bool" : {
"should" : [q1, q2,q3 ...]
},
"minimum_should_match" : 3,
}
理論上:
Lucene查詢語法可以解決問題。 謝謝
http://lucene.apache.org/core/2_9_4/queryparsersyntax.html#Boosting%20a%20Term
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.