GlurG
GlurG

Reputation: 237

Return only _source from a search

Is it possible to only retrieve the _source document(s) when I execute a search query with the (official) nodejs-elasticsearch library? According to the documentation, there seems to be a way, sort of:

Use the /{index}/{type}/{id}/_source endpoint to get just the _source field of the document, without any additional content around it. For example:

curl -XGET 'http://localhost:9200/twitter/tweet/1/_source'

And the corresponding API call in the nodejs library is:

client.getSource([params, [callback]])

However, this method only seems to be able to retrieve documents on an ID basis. I need to issue a full search body (with filters and query_strings and whatnot), which this method doesn't support.

I'm running ES 1.4

Upvotes: 1

Views: 1571

Answers (1)

bittusarkar
bittusarkar

Reputation: 6357

You can use "fields" for this. See a simplified example below. Go ahead and customize your query as per your requirement:

{
    "fields": [
        "_source"
    ], 
    "query": {
        "match_all": {}
    }
}

The value of fields _index, _type, _id and _score will always be present in the response of Search API.

Upvotes: 1

Related Questions