Can I specify result fields in elasticsearch query?


Shaheed

In my dataset, documents contain more than 20 fields with nested objects. Most of them are long text fields. These fields are very important for full text search, but we only need the title, short description and ID in the output.

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

Paul Belloria

I think you are looking for the properties of the search request :fields

Allows to selectively load specific fields for each document represented by a search hit. Internal fields are loaded by default ._source

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

These fields will be automatically loaded with stored fields (set storage mapping to yes), or, if not stored, will be loaded _sourceand extracted from them (allowing to return nested document objects).

Related


ElasticSearch: Can I query .raw fields?

Christina Bo I'm trying to query the .raw version of a field in my elasticsearch (version 5.0.0) index. The field is named "region" and it maps as follows: { "properties": { "region": { "type": "text", "analyzer": "custom_analyzer", "fields

ElasticSearch: Can I query .raw fields?

Christina Bo I'm trying to query the .raw version of a field in my elasticsearch (version 5.0.0) index. The field is named "region" and it maps as follows: { "properties": { "region": { "type": "text", "analyzer": "custom_analyzer", "fields

ElasticSearch: Can I query .raw fields?

Christina Bo I'm trying to query the .raw version of a field in my elasticsearch (version 5.0.0) index. The field is named "region" and it maps as follows: { "properties": { "region": { "type": "text", "analyzer": "custom_analyzer", "fields

Exclude fields in Elasticsearch query

airplane has the following mappings: curl -XPUT 'localhost:9200/testidx?pretty=true' -d '{ "mappings": { "items": { "dynamic": "strict", "properties" : { "title" : { "type": "string" }, "body" : { "type": "string" }

Conditionally query fields in Elasticsearch

Sunil Yella I'm new to Elasticsearch and before posting this question, I've googled for help but don't understand how to write the query I'm trying to write. My problem is that I am querying very few documents that have very few fields "DueDate" and very few "

Elasticsearch - Query Fields for Aggregation

Gotham I'm exploring the ease of querying and aggregating data using elasticsearch. But I can't pivot and aggregate the data in a single query like this: Consider the data: Is there a way to query the following result which pivots and aggregates the values lik

Exclude fields in Elasticsearch query

airplane has the following mappings: curl -XPUT 'localhost:9200/testidx?pretty=true' -d '{ "mappings": { "items": { "dynamic": "strict", "properties" : { "title" : { "type": "string" }, "body" : { "type": "string" }

Exclude fields in Elasticsearch query

airplane has the following mappings: curl -XPUT 'localhost:9200/testidx?pretty=true' -d '{ "mappings": { "items": { "dynamic": "strict", "properties" : { "title" : { "type": "string" }, "body" : { "type": "string" }

Conditionally query fields in Elasticsearch

Sunil Yella I'm new to Elasticsearch and before posting this question, I've googled for help but don't understand how to write the query I'm trying to write. My problem is that I'm querying very few documents that have very few fields "DueDate" and very few "P

Elasticsearch query with two fields

Derek F I am trying to write a query for some products. Products have two fields, title and description. I want to write a query that passes some text and returns products with matching text. I want all products with a match in the title to rank above all prod

Conditionally query fields in Elasticsearch

Sunil Yella I'm new to Elasticsearch and before posting this question, I've googled for help but don't understand how to write the query I'm trying to write. My problem is that I am querying very few documents that have very few fields "DueDate" and very few "

Exclude fields in Elasticsearch query

airplane has the following mappings: curl -XPUT 'localhost:9200/testidx?pretty=true' -d '{ "mappings": { "items": { "dynamic": "strict", "properties" : { "title" : { "type": "string" }, "body" : { "type": "string" }