![](/img/trans.png)
[英]How to do match multiple nested object in one document with inner hits in elasticsearch
[英]How do I query an Elasticsearch nested document within an inner object?
我正在嘗試對Elasticsearch查詢(ES 5.6.2)中嵌套文檔中的字段進行過濾。 嵌套文檔本身就是主文檔內部對象中的一個字段。 映射如下所示:
{
"mappings": {
"container": {
"properties": {
"host": {
"properties": {
"tags_nested": {
"type": "nested",
"properties": {
"tag_key": {
"type": "keyword"
},
"tag_val": {
"type": "keyword"
}
}
}
}
}
}
}
}
}
我想過濾host.tags_nested.tag_keys
,但是我找不到正確的語法來訪問host
內部對象中嵌套的tags_nested
文檔。 當我知道有一些應匹配的內容時,我嘗試了以下查詢,該查詢不返回任何結果:
{
"query": {
"nested": {
"path": "host.tags_nested",
"query": {
"bool": {
"filter": [
{
"term": {
"host.tags_nested.tag_key": "example_key"
}
}
]
}
}
}
}
}
根據ES文檔 ,您可以通過傳遞與嵌套文檔的字段名稱相對應的path
來執行nested
查詢,以在嵌套文檔中進行查詢。 但是,當path
在內部對象中並且需要使用點表示法訪問時,這似乎不起作用。
有任何想法嗎?
嘗試這個。 字詞查詢可搜索我們指定的確切字詞。 因此,為此使用fieldname.keyword
因為在我們為關鍵字建立索引時,關鍵字會存儲確切的文本。
{
"query": {
"nested": {
"path": "host.tags_nested",
"query": {
"bool": {
"filter": [
{
"term": {
"host.tags_nested.tag_key.keyword": "example_key"
}
}
]
}
}
}
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.