Elasticsearch-获取嵌套字段

我只想获取嵌套字段,但不能,因为它不是叶字段。

GET index/_search

{

"size": 10,

"fields": [

"nested_fields"

]

}

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

我在下面尝试过,但是无法匹配嵌套对象中的每个ID和名称。

GET index/_search

{

"size": 10,

"fields": [

"nested_fields.id",

"nested_fields.name"

]

}

结果:

"fields": {

"events.id": [

"13342",

"24232",

"25534",

"63454"

],

"events.name": [

"R1413",

"R1414",

"R1415",

"R1416",

]

}

这是我的预期结果:

fields" : {

"evets" : {

"id" : "234234",

"name" : "RP1524"

},

.... so on

}

回答:

如果您没有某个查询应以某种方式匹配嵌套字段,则可以这样进行:

GET /index/_search

{

"size": 10,

"_source": ["nested_fields.id", "nested_fields.name"]

}

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

{

"query": {

"nested": {

"path": "nested_fields",

"query": {"match_all": {}},

"inner_hits": {}

}

}

}

以上是 Elasticsearch-获取嵌套字段 的全部内容, 来源链接: utcz.com/qa/400401.html

回到顶部