【发布时间】:2015-08-03 17:18:43
【问题描述】:
如何查询包含键值对“key1”-“value1”和“key2”-“value2”的文档?我似乎找不到任何关于此的文档。
我尝试了下面的查询,但即使应该有匹配的文档,它也没有返回任何结果。虽然用 should 替换 must 是可行的,但是当我输入 minimum_should_match = 100% 时,它也不会返回任何结果。
{
"query": {
"bool": {
"must": [
{
"nested": {
"path": "attributes",
"query": {
"bool": {
"must": [
[
{
"match_phrase": {
"attributes.key": "key1"
}
},
{
"match_phrase": {
"attributes.value": "value1"
}
}
],
[
{
"match_phrase": {
"attributes.key": "key2"
}
},
{
"match_phrase": {
"attributes.value": "value2"
}
}
]
]
}
}
}
},
[
{
"match_all": {
}
}
]
]
}
}
}
这是映射的样子:
{
"index_name": {
"mappings": {
"type_name": {
"properties": {
"attributes": {
"type": "nested",
"properties": {
"key": {
"type": "string",
"analyzer": "flat"
},
"value": {
"type": "string",
"analyzer": "flat"
}
}
}
}
},
}
}
}
非常感谢您的帮助。
【问题讨论】:
标签: elasticsearch