【发布时间】:2020-09-04 18:53:24
【问题描述】:
我有 elasticsearch 6.8.8,只是我的问题的一个例子。我想创建一个查询,让我获得值为“1”的“Test”字段的文档,并且我不想获得值为“3”的“Test”字段,我知道我可以只写第一个表达式没有 3,它会给我一份价值为“1”的文件。但我想知道,有什么方法可以让我同时在同一个字段上使用 must 和 must_not 并获得“1”的值?
我写了这个基本的例子来了解我的意思:
{
"from": 0,
"query": {
"nested": {
"path": "attributes",
"query": {
"bool": {
"should": [
{
"bool": {
"must": [
{
"match": {
"attributes.key": {
"query": "Test"
}
}
},
{
"match": {
"attributes.value": {
"query": "1"
}
}
}
],
"must_not": [
{
"match": {
"attributes.key": {
"query": "Test"
}
}
},
{
"match": {
"attributes.value": {
"query": "3"
}
}
}
]
}
}
]
}
}
}
}
}
我使用属性作为嵌套字段,键值字段使用映射作为字符串类型。
【问题讨论】:
标签: elasticsearch search kibana