Arrays of objects do not work as you would expect: you cannot query
each object independently of the other objects in the array. If you
need to be able to do this then you should use the nested data type
instead of the object data type.
Refer to this ES official document on Arrays to get a detailed explanation.
Adding a working example with index data, mapping, search query, and search result
You have to reindex your data, after applying nested data type
Index Mapping:
{
"mappings": {
"properties": {
"attribute_heel-style": {
"type": "nested"
}
}
}
}
Index Data:
{
"attribute_heel-style": [
{
"name": "heel-style",
"label": "Heel Style",
"value": "stiletto",
"value_label": "Stiletto"
},
{
"name": "heel-style",
"label": "Heel Style",
"value": "wedge",
"value_label": "Wedge"
}
]
}
Search Query:
{
"query": {
"nested": {
"path": "attribute_heel-style",
"query": {
"bool": {
"filter": [
{
"match": {
"attribute_heel-style.value_label": "Wedge"
}
}
]
}
},
"inner_hits":{}
}
}
}
Search Result:
"inner_hits": {
"attribute_heel-style": {
"hits": {
"total": {
"value": 1,
"relation": "eq"
},
"max_score": 0.0,
"hits": [
{
"_index": "65585632",
"_type": "_doc",
"_id": "1",
"_nested": {
"field": "attribute_heel-style",
"offset": 1
},
"_score": 0.0,
"_source": {
"name": "heel-style",
"label": "Heel Style",
"value": "wedge",
"value_label": "Wedge" // note this
}
}
]
}
}
}
}
Update 1:
{
"mappings": {
"company:product:mapping": {
"properties": {
"attribute_heel-style": {
"type": "nested", // note this
"properties": {
"label": {
"type": "keyword"
},
"name": {
"type": "keyword"
},
"source": {
"type": "keyword"
},
"value": {
"type": "keyword"
},
"value_label": {
"type": "keyword"
}
}
}
}
}
}
}