Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Elasticsearch: Return only nested inner_hits

I have the following query:

GET /networkcollection/branch_routers/_search/
{
  "query": {
    "nested": {
      "path": "queries",
      "query": {
        "bool": {
          "must": [
            { "match": 
              { "queries.dateQuery": "20160101T200000.000Z" }
            }
          ]
        }
      },
      "inner_hits" : {}
    }
  }
}

This returns both the "hits" object (the entire document), as well as the "inner_hits" object (nested inside of hits).

Is there a way to for me to only return the matched "queries" element(s) which appear in the "inner_hits" results, without getting the whole document?

like image 621
blgrnboy Avatar asked Feb 23 '16 21:02

blgrnboy


1 Answers

Should be able to achieve it by disabling source-field at top-level by specifying "_source" : false

POST /networkcollection/branch_routers/_search/
{
  "_source" : false,
  "query": {
    "nested": {
      "path": "queries",
      "query": {
        "bool": {
          "must": [
            { "match": 
              { "queries.dateQuery": "20160101T200000.000Z" }
            }
          ]
        }
      },
      "inner_hits" : {}
    }
  }
}
like image 57
keety Avatar answered Oct 15 '22 07:10

keety