[英]Nested query on ElasticSearch
我有一個彈性搜索索引,它以下列方式存儲文檔:
{
categorisedTags:
{ urlTags: { L: [] },
commodityTags: { L: [Array] },
tags: { L: [] } },
newOptions: [],
created_at: 'Mon, 07 Oct 2019 12:55:34 GMT',
name: 'Template ',
}
我需要通過'commodityTags'查詢索引,所以給定一個字符串,它應該返回該字符串包含在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 上進行這種嵌套查詢?
可以像下面這樣創建嵌套查詢
"query": {
"nested": {
"path": "categorisedTags",
"query": {
"bool": {
"must": [
{
"term": {
"categorisedTags.commodityTags": {
"value": "oil"
}
}
}
]
}
},
"inner_hits": {}
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.