我无法在嵌套文档中组合term,must_not查询。ElasticSearch中的术语,嵌套文档和must_not查询不兼容?
意识例子可以在这里找到:http://sense.qbox.io/gist/be436a1ffa01e4630a964f48b2d5b3a1ef5fa176
这里我映射:
{
"mappings": {
"docs" : {
"properties": {
"tags" : {
"type": "nested",
"properties" : {
"type": {
"type": "string",
"index": "not_analyzed"
}
}
},
"label" : {
"type": "string"
}
}
}
}
}
在此指数两个文件:
{
"tags" : [
{"type" : "POST"},
{"type" : "DELETE"}
],
"label" : "item 1"
},
{
"tags" : [
{"type" : "POST"}
],
"label" : "item 2"
}
当我询问该指数是这样的:
{
"query": {
"nested": {
"path": "tags",
"query": {
"bool": {
"must": {
"term": {
"tags.type": "DELETE"
}
}
}
}
}
}
}
我有一重击(这是正确的)
当我想不包含标签“删除”的文件,该查询:
{
"query": {
"nested": {
"path": "tags",
"query": {
"bool": {
"must_not": {
"term": {
"tags.type": "delete"
}
}
}
}
}
}
}
我已经有2次点击(这是不正确的)。 这个问题看起来非常接近这个(Elasticsearch array must and must_not),但它不是...
你能给我一些线索来解决这个问题吗?
谢谢
谢谢,它的工作原理。你能解释你为什么这么做吗? – user3393203
仅仅因为它没有“include_in_root”是不可能的。现在,您可以将所有“tags.type”视为一个数组,而不是拥有复杂的嵌套过滤器/查询系统。这样,你可以说“像给我所有的文档没有在标签类型数组中的'DELETE'”。 有时候很难说出这些东西,但希望这是有道理的! –
它不适合我。这既奇怪又伤心。这可能是因为我使用'terms'和'integer'? –