I am wondering how to construct a query that can return documents where each contains a list field, but with duplicate values in that field. Here's an example setup:
PUT nestedtest
{
"mappings": {
"type": {
"properties": {
"history": {
"type": "nested"
}
}
}
}
}
PUT nestedtest/type/1
{
"name" : "Bob",
"history" : [
{
"date" : "2016-01-01",
"status" : "None" ,
"color" : "red"
},
{
"date" : "2016-01-01",
"status" : "None" ,
"color" : "blue"
},
{
"date" : "2016-01-02",
"status" : "None",
"color" : "green"
}
]
}
PUT nestedtest/type/2
{
"name" : "Jane",
"history" : [
{
"date" : "2016-01-01",
"status" : "None",
"color" : "red"
},
{
"date" : "2016-01-01",
"status" : "Done",
"color" : "blue"
},
{
"date" : "2016-01-02",
"status" : "None",
"color" : "green"
}
]
}
My interest is in querying the "history" field, which has been mapped as a nested field, in each document and checking for cases where the "date" field matches and where the "status"=="None" field match. So in this case, the query will return the first document with "_id" : 1, because the first and second item of it's "history" field contains the same value for "date" and "status"=="None" respectively.