If I have following index mapping for nested type, can I filter on two different fields in the same document?
Mapping:
{
"mappings": {
"records": {
"properties": {
"record": {
"type": "nested",
"properties": {
"IntFieldName": { "type": "string" },
"IntFieldValue": { "type": "integer" },
"BoolFieldName": { "type": "string" },
"BoolFieldValue": { "type": "boolean" },
"KeywordFieldName": { "type": "string" },
"KeywordFieldValue": { "type": "keyword" }
}
}
}
}
}
}
Index:
{
"record": [
{
"IntFieldName": "myint1",
"IntFieldValue": 1,
"BoolFieldName": "mybool1",
"BoolFieldValue": true,
"KeywordFieldName": "mykeyword1",
"KeywordFieldValue": "foo"
},
{
"IntFieldName": "myint2",
"IntFieldValue": 2,
"BoolFieldName": "mybool2",
"BoolFieldValue": false,
"KeywordFieldName": "mykeyword2",
"KeywordFieldValue": "bar"
}
]
}
I want to run query equal to something like this:
WHERE IntFieldName = "myint1"
AND IntFieldValue = 1
AND IntFieldName = "myInt2"
AND IntFieldValue = 2
Following is the query, but it does not fetch any results. Is my query incorrect or is it not possible in ES?
Query:
{
"query": {
"nested": {
"path": "record",
"query": {
"bool": {
"filter": [
{ "match": { "record.IntFieldName": "myint1" }},
{ "match": { "record.IntFieldValue": 1 }},
{ "match": { "record.IntFieldName": "myint2" }},
{ "match": { "record.IntFieldValue": 2 }}
]
}
}
}
}
}