2012-12-27 160 views
0

我們正在對嵌套對象進行match_phrase查詢,其中嵌套對象只有一個字符串值。彈性搜索嵌套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

在你的情況下,單獨的數組值應該在它們的偏移量中有很大的差距以避免短語匹配。 有同場的實例之間的默認配置的差距,但這種差距的默認值是0。

你應該在字段映射更改:

"attr": { "type": "string", 
"index": "analyzed", 
"include_in_all": true, 
"analyzer": "keyword", 
"position_offset_gap": 100 
} 
+0

它不會工作。 :( – anks2089