'Elasticsearch, Exists filter for nested objects not working
My mapping is:
"properties": {
"user": {
"type": "nested",
"properties": {
"id": {
"type": "integer"
},
"is_active": {
"type": "boolean",
"null_value": false
},
"username": {
"type": "string"
}
}
},
I want to get all documents that do not have a user field.
I tried:
GET /index/type/_search
{
"query": {
"bool": {
"must_not": [
{
"exists": {
"field": "user"
}
}
]
}
}
}
Which returns all documents. Based on ElasticSearch 2.x exists filter for nested field doesn't work, I also tried:
GET /index/type/_search
{
"query": {
"nested": {
"path": "user",
"query": {
"bool": {
"must_not": [
{
"exists": {
"field": "user"
}
}
]
}
}
}
}
}
Which returns 0 documents.
What is the correct query to get all documents missing the user field?
elasticsearch">
elasticsearchelasticsearch-2.0">
elasticsearch-2.0elasticsearch-dsl">
elasticsearch-dsl
Solution 1:[1]
Try using the parent of the user, here obj
GET users/users/_search
{
"query": {
"bool": {
"must_not": [
{
"exists": {
"field": "obj.user"
}
}
]
}
}
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Ryadh Khsib |
