I am working on elasticsearch and using term in search query. Please have a look on sample indexed data below:
"_source": {
"type": "ITEM",
"primaryKey": "3923",
"displayName": "Lumia 505",
"attributes": {
"n26273": "Lumia 505",
"n26275": "Mobile"
},
"mappings": {
"Primary Hierarchy": [
"Nokia"
]
}
}
For searching data against my any search text I am using below query which is working fine:
{
"query":{
"bool":{
"must":[
{
"query_string":{
"query":"----MySearchTextHere----",
"default_operator":"AND"
}
},
{
"term":{
"type":"item"
}
}
]
}
},
"size":10,
"from":0
}
Queries:
1. How can I add term in query to search against field "mappings.Primary Hierarchy" which is an array?
2. How can I achieve #1 without mentioning nested field name as nested field name would be dynamic? only field name mappings is constant.