Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

No more _source if script_fields is used in elasticsearch query

Tags:

I am running a simple query like so:

{   "query": {     "term": {       "statuses": "active"     }   },   "script_fields": {     "test": {       "script": "_source.name"     }   } } 

The problem is that once I introduce the script_fields, I no longer get _source in my results.

I have tried:

{   "fields": [     "_all"   ],   "query": {     "term": {       "statuses": "active"     }   },   "script_fields": {     "email": {       "script": "_source.name"     }   } } 

and

{   "fields": [     "*"   ],   "query": {     "term": {       "statuses": "active"     }   },   "script_fields": {     "email": {       "script": "_source.name"     }   } } 

But they did not make any difference. Is there a way to get _source returned in addition to the script_fields?

like image 367
F21 Avatar asked Aug 08 '12 00:08

F21


People also ask

How do I retrieve data from Elasticsearch?

You can use the search API to search and aggregate data stored in Elasticsearch data streams or indices. The API's query request body parameter accepts queries written in Query DSL. The following request searches my-index-000001 using a match query. This query matches documents with a user.id value of kimchy .

What are fields in elastic search?

Fields are the smallest individual unit of data in Elasticsearch. These are customizable and could include, for example: title, author, date, summary, team, score, etc. Each field has a defined datatype and contains a single piece of data.


1 Answers

In the fields array, make it load _source:

{   "stored_fields": [     "_source"   ],   "query": {     "term": {       "statuses": "active"     }   },   "script_fields": {     "email": {       "script": "_source.name"     }   } } 
like image 93
F21 Avatar answered Sep 18 '22 23:09

F21