First the look of my fields.
- id
- parent_id
- type
I want to write a query that show all the results that have this criteria :
- Each result's id shouldn't be a parent_id of another result (parent_id 0 doesn't count)
- The results should only be of type 1
For example :
Id = 1, parent_id = 11, type = 1
Id = 2, parent_id = 1, type = 2
Id = 3, parent_id = 4, type =2
Id = 4, parent_id = 7, type = 1
Id = 5, parent_id = 8, type = 2
Id = 6, parent_id = 9, type = 1
Id = 7, parent_id = 0, type = 3
Id = 8, parent_id = 0, type = 3
Id = 9, parent_id = 0, type = 3
So from these data, the result should give me the data of Id 6 only in this example
In other words, I want to verify before showing the result that each of the current data does not match a parent_id of any other data.
In other other words, I want to put a must_not id = parent_id and must type = 1.
How to do this in elasticsearch?
I hope my question is clear!