我有一个 flex 搜索索引,该索引以以下方式存储文档:
{
categorisedTags:
{ urlTags: { L: [] },
commodityTags: { L: [Array] },
tags: { L: [] } },
newOptions: [],
created_at: 'Mon, 07 Oct 2019 12:55:34 GMT',
name: 'Template ',
}
我需要通过“commodityTags”查询索引,因此给定一个字符串,它应该返回该字符串包含在商品标签数组中的所有文档。
我尝试过:
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);
};
但没有运气,总是返回0命中。如何在ES上进行这种嵌套查询?
最佳答案
Nested query可以如下创建
询问
"query": {
"nested": {
"path": "categorisedTags",
"query": {
"bool": {
"must": [
{
"term": {
"categorisedTags.commodityTags": {
"value": "oil"
}
}
}
]
}
},
"inner_hits": {}
}
}
关于javascript - 在ElasticSearch上的嵌套查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58270455/