I want to filter the document by nested field value. My document is like this and I want to filter it by Color parameter:
{
"_index": "myindex",
"_type": "product",
"_id": "984984",
"_source": {
"id": "98418",
"name": "Product1",
..
"parameters": {
"Color": [
"Black",
"Gold"
]
}
}
}
My mapping is:
{
"myindex": {
"mappings": {
"product": {
"properties": {
..
"parameters": {
"type": "nested",
"properties": {
"Color": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
..
}
}
}
}
}
}
And my filter query is following:
{
"query": {
"bool": {
"filter": {
"nested": {
"path": "parameters",
"query": {
"term": {
"parameters.Color":"Gold"
}
}
}
}
}
}
}
But unfortunatelly I'm getting zero documents and I do not understand why?
Thank you
EDIT
Event this is working:
{
"query": {
"nested": {
"path": "parameters",
"query": {
"bool": {
"must": [
{ "match": { "parameters.Color": "Gold" }}
]
}
}
}
}
}
..but this is not:
{
"query": {
"nested": {
"path": "parameters",
"query": {
"bool": {
"filter": [
{ "term": { "parameters.Color": "Gold" }}
]
}
}
}
}
}
Why??