Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Need to return source fields only, without any metadata - how to use plugin?

We have a requirement that we return just the source fields in search results, without any of the metadata. From searching, I gather that this is not possible with elasticsearch, but I did find a reference to maybe using a plugin in this thread:

Filter out metadata fields and only return source fields in elasticsearch

The plugin that was linked was this one:

https://github.com/imotov/elasticsearch-just-source/blob/master/src/main/java/org/elasticsearch/examples/justsource/rest/action/RestJustSourceAction.java

I'm still learning about elasticsearch, but can someone explain how I would implement and deploy that plugin in our elasticsearch configuration?

Thanks, Jim

like image 438
user555303 Avatar asked May 04 '17 02:05

user555303


People also ask

How do I capture a specific field in Elasticsearch?

There are two recommended methods to retrieve selected fields from a search query: Use the fields option to extract the values of fields present in the index mapping. Use the _source option if you need to access the original data that was passed at index time.

What is _source in Elasticsearch query?

The _source field contains the original JSON document body that was passed at index time. The _source field itself is not indexed (and thus is not searchable), but it is stored so that it can be returned when executing fetch requests, like get or search.

How do I search all fields in Elasticsearch?

Either the query_string query or the match query would be what you're looking for. query_string will use the special _all field if none is specified in default_field , so that would work out well. And with match you can just specify the _all as well. Save this answer.

What is Elasticsearch metadata?

Metadata in Elasticsearch refers to additional information stored for each document. This is achieved using the specific metadata fields available in Elasticsearch. The default behavior of some of these metadata fields can be customized during mapping creation.


1 Answers

As stated in the first link you referenced, it is possible to do it with response filtering which is not a plugin but a standard feature of ES:

GET /index/type/_search?filter_path=hits.hits._source

If you want to get rid of hits.hits._source you can use jq

curl -XGET localhost:9200/index/type/_search?filter_path=hits.hits._source | jq '.hits.hits[]._source'
like image 105
Val Avatar answered Nov 15 '22 05:11

Val