[英]Elastic search nested match_phrase issue
我們正在對嵌套對象執行match_phrase查詢,其中嵌套對象僅具有字符串值。
我們打算查找字符串短語出現的地方。
假設,
1)映射如下。
"attr": {
"type": "nested",
"properties": {
"attr": {
"type": "multi_field",
"fields": {
"attr": { "type": "string", "index": "analyzed", "include_in_all": true, "analyzer": "keyword" },
"untouched": { "type": "string", "index": "analyzed", "include_in_all": false, "analyzer": "not_analyzed" }
}
}
}
}
2)數據就像。
對象A:
"attr": [
{
"attr": "beverage"
},
{
"attr": "apple wine"
}
]
對象B:
"attr": [
{
"attr": "beverage"
},
{
"attr": "apple"
},
{
"attr": "wine"
}
]
3)因此,在查詢像
{
"query": {
"match": {
"_all": {
"query": "apple wine",
"type": "phrase"
}
}
}
}
我們只期望對象A,但是不幸的是,對象B也即將到來。
請期待您的建議。
在您的情況下,單獨的數組值的偏移量應有較大的間隙,以避免短語匹配。 同一字段的實例之間存在默認的可配置間隙,但是此間隙的默認值為0。
您應該在字段映射中更改它:
"attr": { "type": "string",
"index": "analyzed",
"include_in_all": true,
"analyzer": "keyword",
"position_offset_gap": 100
}
您還需要告訴查詢以一個嵌套文檔搜索所有術語:
"query": {
"nested": {
"path": "attr",
"query": {
"match": {
"attr": {
"query": "apple wine",
"operator": "and"
}
}
}
}
}
很好的信息來源是http://www.spacevatican.org/2012/6/3/fun-with-elasticsearch-s-children-and-nested-documents/
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.