我们在嵌套对象上执行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也即将到来。
请期待您的建议。
发布于 2013-01-02 14:20:06
在您的例子中,单独的数组值在其偏移量中应该有较大的间隙,以避免短语匹配。在相同字段的实例之间存在默认的可配置间距,但此间距的默认值为0。
您应该在字段映射中更改它:
"attr": { "type": "string",
"index": "analyzed",
"include_in_all": true,
"analyzer": "keyword",
"position_offset_gap": 100
}发布于 2014-04-02 18:00:37
您还需要告诉查询在一个嵌套文档中搜索所有术语:
"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/是一个很好的信息来源。
https://stackoverflow.com/questions/14053657
复制相似问题