6

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

Community
  • 1
  • 1
user555303
  • 1,146
  • 3
  • 20
  • 44

1 Answers1

5

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'
Val
  • 207,596
  • 13
  • 358
  • 360
  • we know and have been trying with filter_path, but unfortunately, that still leaves some remnants like {"hits": {"hits": [ {"_source": . We want the response to be just the hits elements as an array. – user555303 May 04 '17 at 12:13
  • That's a transformation you can do on the client side very easily or you can use `jq` – Val May 04 '17 at 12:24
  • See my edited answer, which shows how to use `jq` to achieve what you want. – Val May 04 '17 at 12:26
  • thanks for that and, actually when I was checking out your suggestion, I noticed that the 'actual' response from ES is straight string, so even using 'sed' does work also. Cool :)! – user555303 May 05 '17 at 17:17