誰能詳細解釋 zero_terms_query elasticsearch,我瀏覽了 elasticsearch 檔案,但我沒有正確理解
uj5u.com熱心網友回復:
讓我們通過我們自己的例子來理解它,因為我們可以使用英語分析器創建一個索引,該索引將洗掉所有英語停用詞,to be or not to be 例如 Elasticsearch 給出的示例。
索引映射
{
"mappings" : {
"properties" : {
"title" : {
"type" : "text",
"analyzer" : "english"
}
}
}
}
索引幾個示例檔案
{
"title": "sudeesh"
}
{
"title": "to be or not to be"
}
搜索查詢從查詢??中洗掉所有停用詞,因為我們正在使用match將相同english分析器應用于搜索查詢的查詢。
{
"query": {
"match": {
"title": {
"query": "to be or not to be",
"operator": "and",
"zero_terms_query": "all"
}
}
}
}
搜索結果
"hits": [
{
"_index": "72442818",
"_id": "1",
"_score": 1.0,
"_source": {
"title": "to be or not to be"
}
},
{
"_index": "72442818",
"_id": "2",
"_score": 1.0,
"_source": {
"title": "sudeesh"
}
}
]
請注意,上面的搜索查詢回傳我們指定的檔案,"zero_terms_query": "all"因此它將被視為match_all并回傳所有檔案。
如果您洗掉"zero_terms_query": "all"它,它將被視為noneElasticsearch 檔案中提到的默認值,并且您不會得到任何搜索結果,因為在 Elasticsearch 中沒有要搜索的搜索詞。
當您的查詢中包含所有停用詞并且想要回傳更多搜索結果而不是 0 搜索結果時,這尤其有用。
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/485200.html
