I have an elastic search index which is storing documents in the following way:
{
categorisedTags:
{ urlTags: { L: [] },
commodityTags: { L: [Array] },
tags: { L: [] } },
newOptions: [],
created_at: 'Mon, 07 Oct 2019 12:55:34 GMT',
name: 'Template ',
}
I need to query the index by 'commodityTags', so given a string, it should return all documents where the string is included in the commodityTags array.
I have tried with:
service.queryTags = async (index, values) => {
const { hits } = await esClient.search({
index,
type: '_doc',
body: {
query: {
term: {
'categorisedTags.commodityTags': 'oil'
}
},
},
});
return hits.hits.map(({ _source }) => _source);
};
But no luck, always returns 0 hits. How can I do this kind of nested queries on ES ?