Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I specify the result fields in elasticsearch query?

In my dataset, a document contains 20+ fields with nested objects. Most of them are long text fields. These fields are important for full-text search but we only need to show the title, short-description and Id in output.

Is it possible to specify the output fields in ElasticSearch for a full text query? (like projection in MongoDB)

like image 875
Shahed Avatar asked Jan 24 '14 22:01

Shahed


1 Answers

I think you're looking for the fields property of a search request:

Allows to selectively load specific fields for each document represented by a search hit. Defaults to load the internal _source field.

{
    "fields" : ["user", "postDate"],
    "query" : {
        "term" : { "user" : "kimchy" }
    }
}

The fields will automatically load stored fields (store mapping set to yes), or, if not stored, will load the _source and extract it from it (allowing to return nested document object).

like image 160
Paul Bellora Avatar answered Oct 04 '22 16:10

Paul Bellora