Last active
March 15, 2017 12:09
-
-
Save Erni/7484095 to your computer and use it in GitHub Desktop.
Elasticsearch missing filter with nested objects
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
PUT http://localhost:9200/test2/IR/1 | |
{ | |
"id": 1, | |
"priosenio": { | |
"claim": 1, | |
"ir": 1, | |
"senioclaim": 1, | |
"seniostatus": 1 | |
} | |
} | |
PUT http://localhost:9200/test2/IR/2 | |
{ | |
"priosenio": { | |
"claim": 2, | |
"ir": 2, | |
"senioclaim": 2, | |
"seniostatus": 2 | |
} | |
} | |
PUT http://localhost:9200/test2/IR/3 | |
{ | |
"id": 3, | |
"priosenio": { | |
"ir": 3, | |
"senioclaim": 3, | |
"seniostatus": 3 | |
} | |
} | |
PUT http://localhost:9200/test2/IR/4 | |
{ | |
"id": 4, | |
"priosenio": [] | |
} | |
PUT http://localhost:9200/test2/IR/5 | |
{ | |
"id": 5 | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Elasticsearch missing filter with nested objects |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
PUT http://localhost:9200/test2 | |
{ | |
"mappings": { | |
"IR": { | |
"_all": { | |
"enabled": false | |
}, | |
"_id": { | |
"path": "id" | |
}, | |
"properties": { | |
"id": { | |
"type": "string", | |
"null_value": "", | |
"index": "not_analyzed" | |
}, | |
"priosenio": { | |
"type": "nested", | |
"properties": { | |
"claim": { | |
"type": "integer", | |
"null_value": -2147483648 | |
}, | |
"ir": { | |
"type": "integer", | |
"null_value": -2147483648 | |
}, | |
"senioclaim": { | |
"type": "integer", | |
"null_value": -2147483648 | |
}, | |
"seniostatus": { | |
"type": "integer", | |
"null_value": -2147483648 | |
} | |
} | |
} | |
} | |
} | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// this one works as expected, returning only doc with id 3, since it has "claim" attribute missing | |
POST http://localhost:9200/test2/IR/_search | |
{ | |
"query": { | |
"filtered" : { | |
"filter" : { | |
"nested" : { | |
"path": "priosenio", | |
"filter": { | |
"missing" : { | |
"field" : "claim" | |
} | |
} | |
} | |
} | |
} | |
} | |
} | |
// however this query returns all the docs, and I am expecting only docs 4 and 5 (since it works with no-nested objects) | |
POST http://localhost:9200/test2/IR/_search | |
{ | |
"query": { | |
"filtered" : { | |
"filter": { | |
"missing" : { | |
"field" : "priosenio" | |
} | |
} | |
} | |
} | |
} | |
// if I run the query as I would if priosenio was not a nested object, it returns all the docs (instead of only 4 and 5) | |
POST http://localhost:9200/test2/IR/_search | |
{ | |
"filter": { | |
"missing" : { | |
"field" : "priosenio" | |
} | |
} | |
} | |
// this query solves the problem and returns all the docs (4 and 5) with "priosenio" missing | |
POST http://localhost:9200/test2/IR/_search | |
{ | |
"filter": { | |
"not": { | |
"nested": { | |
"path": "priosenio", | |
"filter": { | |
"match_all": {} | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment