Elasticsearch - get nested fields

前端 未结 1 899
被撕碎了的回忆
被撕碎了的回忆 2021-01-13 11:50

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

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


        
1条回答
  •  隐瞒了意图╮
    2021-01-13 12:04

    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": {}
        }
      }
    }
    

    0 讨论(0)
提交回复
热议问题