我在ElasticSearch中有一些数据:
{
"title": "example",
"labels": [
{
"key": "region",
"value": "us-la"
},
{
"key": "url",
"value": "www.google.com"
}
]
},
{
"title": "example",
"labels": [
{
"key": "region",
"value": "us-nyc"
},
{
"key": "url",
"value": "www.stackoverflow.com"
}
]
}
ElasticSearchMap:
{
"properties": {
"title": {
"type": "text"
},
"labels": {
"type": "nested",
"properties": {
"key": {
"type": "text"
}
"value": {
"type": "text"
}
}
}
}
}
当我想建议labels.key
:
GET /my-index/_search
{
"query": {
"nested": {
"path": "labels",
"query": {
"match": {
"labels.key": "us"
}
}
}
}
}
回应是:
{
"title": "example",
"labels": [
{
"key": "region",
"value": "us-la"
},
{
"key": "url",
"value": "www.google.com"
}
]
}
它在文档中返回,但我只想要labels
字段的匹配对象,如下所示:
{
"key": "region",
"value": "us-la"
}
这将便于限制响应。
我试过inner_hit
,但仍然不工作。
任何帮助/建议将不胜感激。
1条答案
按热度按时间x7rlezfr1#
我认为你在字段“label.value”中搜索,因为唯一的字段包含值“us-la”。
我使用了“inner_hits”并获得了匹配。
结果: