【发布时间】:2014-03-07 15:28:32
【问题描述】:
我无法在嵌套文档中组合 term、must_not 查询。
可以在此处找到 Sense 示例: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"
}
}
}
}
}
}
}
我中了一击(这是正确的)
当我想获取不包含标签“DELETE”的文档时,使用以下查询:
{
"query": {
"nested": {
"path": "tags",
"query": {
"bool": {
"must_not": {
"term": {
"tags.type": "delete"
}
}
}
}
}
}
}
我有 2 次点击(这是不正确的)。 这个问题似乎非常接近这个问题(Elasticsearch array must and must_not),但它不是......
你能给我一些解决这个问题的线索吗?
谢谢
【问题讨论】:
标签: elasticsearch nested