我有嵌套字段的索引映射:
new MyAsyncTask(MainActivity.this).execute();
我想在 "customerpropertieses": {
"_parent": {
"type": "customerprofile"
},
"_routing": {
"required": true
},
"properties": {
"id": {
"type": "string"
},
"parentId": {
"type": "string"
},
"properties": {
"type": "nested",
"properties": {
"extentionPropertyId": {
"type": "long"
},
"propertyName": {
"type": "string"
},
"value": {
"type": "string"
}
}
}
}
}
我手工生成的查询是:
propertyName=criteria1 & value=value1 & propertyName=criteria2 & value=value2
我得到0结果,我当然有这些特征的数据。当我只查看{
"from": 0,
"size": 10,
"sort": [
{
"_score": {
"order": "desc"
}
}
],
"query": {
"nested": {
"query": {
"bool": {
"must": [
{
"match": {
"properties.propertyName": {
"query": "criteria1 "
}
}
},
{
"match": {
"properties.value": {
"boost": 10.0,
"query": "value1"
}
}
},
{
"match": {
"properties.propertyName": {
"query": "criteria2"
}
}
},
{
"match": {
"properties.value": {
"boost": 10.0,
"query": "value2"
}
}
}
]
}
},
"path": "properties",
"inner_hits": {
"explain": false
},
"_name": "nested_properties"
}
}
}
或使用propertyName = criteria2&时,搜索工作正常。值=值2'
问题是如何使用&堆叠搜索条件?在嵌套查询?
答案 0 :(得分:1)
尝试以下查询。从你的查询的外观我想猜你想要匹配两个嵌套文档的文件,其中值分别为value1,criteria1和value2,criteria2分别为value和criteria字段。
{
"from": 0,
"size": 10,
"sort": [{
"_score": {
"order": "desc"
}
}],
"query": {
"bool": {
"must": [{
"nested": {
"query": {
"bool": {
"must": [{
"match": {
"properties.propertyName": {
"query": "criteria2"
}
}
}, {
"match": {
"properties.value": {
"boost": 10.0,
"query": "value2"
}
}
}]
}
},
"path": "properties",
"inner_hits": {
"explain": false
},
"_name": "nested_properties"
}
}, {
"nested": {
"query": {
"bool": {
"must": [{
"match": {
"properties.propertyName": {
"query": "criteria1 "
}
}
}, {
"match": {
"properties.value": {
"boost": 10.0,
"query": "value1"
}
}
}]
}
},
"path": "properties",
"inner_hits": {
"explain": false
},
"_name": "nested_properties"
}
}]
}
}
}
我索引以下文档进行猜测并修改了查询 以下文档将与上面的查询匹配
{
"parentId" : "3434",
"properties" : [{
"extentionPropertyId" : 24,
"propertyName" : "criteria1",
"value" : "value1"
},{
"extentionPropertyId" : 24,
"propertyName" : "criteria2",
"value" : "value2"
}]
}
希望这会有所帮助。 感谢