簡體   English   中英

僅返回 elasticsearch 查詢中的頂級字段?

[英]Return only top level fields in elasticsearch query?

我有一個包含嵌套字段的文檔。 例子:

    "mappings": {
        "blogpost": {
          "properties": {
            "title": { "type": "text"  },
            "body":  { "type": "text"  },
            "comments": {
              "type": "nested", 
              "properties": {
                "name":    { "type": "text"  },
                "comment": { "type": "text"  },
                "age":     { "type": "short"   },
                "stars":   { "type": "short"   },
                "date":    { "type": "date"    }
              }
            }
          }
        }
  }
}

可以修改查詢以使響應僅包含非嵌套字段嗎?

在此示例中,響應將僅包含bodytitle

使用_source您可以排除/包含字段

GET /blogpost/_search
{
    "_source":{
        "excludes":["comments"]
    }
}

但是您必須明確地將字段名稱放在排除中,我正在尋找一種方法來排除所有嵌套字段而不知道它們的字段名稱

您可以通過 static 方式實現這一點,這意味着您使用excludes關鍵字輸入了字段名稱,例如:

GET your_index/_search
{
    "_source": {
        "excludes": "comments"  
    },
    "query": {
        "match_all" : {}
    }
}

excludes可以采用字符串array 不只是一個字符串。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM