I tried to search inside array of object using match query but I got all the values inside the array, because the array is not of type nested.
I am using dynamic template to create index.
Is there any way to search single object which matches the given criteria instead of getting all the values in the array? I had tried multiple methods using query but the issue is the template is not of type nested.
Kindly provide any insights regarding this or any workaround is there to get single object from array which matches.
I am not using type nested since it has certain limitations.
My document looks like this.
{
"productpk_s": "PROD001",
"product": {
"productpk_s": "PROD001",
"mfgname_s": "TEST MFG"
},
"salesorder": [
{
"salesorderpk_s": "SO001",
"productpk_s": "PROD001",
"vendorname_s": "Mitsubishi"
},
{
"salesorderpk_s": "SO002",
"productpk_s": "PROD001",
"vendorname_s": "Sony"
},
{
"salesorderpk_s": "SO003",
"productpk_s": "PROD001",
"vendorname_s": "Sony"
},
{
"salesorderpk_s": "SO004",
"productpk_s": "PROD001",
"vendorname_s": "Sony"
},
{
"salesorderpk_s": "SO005",
"productpk_s": "PROD001",
"vendorname_s": "Sony"
}
]
}
Sample query I tried:
{
"_source": [
"product.productpk_s",
"salesorder.salesorderpk_s",
"salesorder.vendorname_s"
],
"query": {
"bool": {
"must": [
{
"term": { "salesorder.vendorname_s.keyword": "Mitsubishi" }
}
]
}
}
}
I think I am doing something wrong.
Kindly suggest, how the search can be performed without type nested in dynamic template.