弹性搜索 - 获取嵌套字段 [英] Elasticsearch - get nested fields

查看:130
本文介绍了弹性搜索 - 获取嵌套字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  GET索引/ _search $ b $我想要只收集嵌套字段,但不能由于它不是叶子字段。 b {
size:10,
fields:[
nested_fields
]
}
/ pre>

错误:reason:field [nested_fields] not not a leaf field p>

我尝试下面但不能匹配嵌套对象中的每个id和名称。

  GET索引/ _search 
{
size:10,
fields:[
nested_fields.id,
nested_fields.name
]
}

结果:



$ $ $ $ $ $ $ $ $ $ $ $ $ $ $$$$$$$ 25534,
63454
],
events.name:[
R1413,
R1414,
R1415,
R1416,
]
}

这是我的预期结果:

  fields:{
evets:{
id :234234,
name:RP1524
},
.... so on
}
/ pre>

解决方案

如果您没有某个特定查询应该与嵌套字段匹配,您可以这样做:

  GET / index / _search 
{
size:10,
_source:[nested_fields.id,nested_fields.name]
}

如果您还有一个嵌套的查询,并且您想返回匹配的嵌套文档,则可以这样执行(使用 inner_hits ):

  {
查询:{
嵌套:{
path:nested_fields,
query:{match_all:{}},
inner_hits:{}
}
}
}


I want to get only nested fields, but cannot since it's not leaf fields.

GET index/_search
{
    "size": 10,
    "fields": [
       "nested_fields"
    ]
}

ERROR : "reason": "field [nested_fields] isn't a leaf field"

I tried below but cannot match each id and name in nested object.

GET index/_search
    {
        "size": 10,
        "fields": [
           "nested_fields.id",
           "nested_fields.name"
        ]
    }

result :

"fields": {
               "events.id": [
                  "13342",
                  "24232",
                  "25534",
                  "63454"
               ],
               "events.name": [
                  "R1413",
                  "R1414",
                  "R1415",
                  "R1416",
               ]
            }

Here is my expected result:

fields" : {
  "evets" : {
      "id" : "234234",
      "name" : "RP1524"
   },
    .... so on
}

解决方案

If you don't have a certain query that should match the nested fields somehow, you can do it like this:

GET /index/_search
{
  "size": 10,
  "_source": ["nested_fields.id", "nested_fields.name"]
}

If you also have a nested query and you want to return the nested docs that matched you can do it like this (with inner_hits):

{
  "query": {
    "nested": {
      "path": "nested_fields",
      "query": {"match_all": {}}, 
      "inner_hits": {}
    }
  }
}

这篇关于弹性搜索 - 获取嵌套字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆