Elasticsearch Query to Return Results in a Common Number of Fields


Is there a way to return result with a common set of fields

E.g. I have two records or documents.

1st Record
ID: 001
Price: 12

2nd Record
Price: 20
Remarks: Do not store outdoors

I am looking at for match-all like query to give me the following result
ID: 001
Price: 12
Remarks: NIL
Price: 20
Remarks: Do not store outdoors

There should be some values in the "Remarks" field for the first record. It could be blank or a default value

Anyone knows if this could be done?

(David Pilato) #2

At index time, you can use https://www.elastic.co/guide/en/elasticsearch/reference/current/null-value.html
And also store the field.

Then ask for this field at query time

Or at search time only (slower): https://www.elastic.co/guide/en/elasticsearch/reference/2.2/search-request-script-fields.html

It will never change your _source doc.
May be node ingest could help in coming elasticsearch 5.0.


If I were to do it at indexing, will it require more storage since no value fields are filled with values?

(Ivan Brusic) #4

I would use a not + exist filter and let your client handle determining if
the field is null.




How about storage? Will setting empty values to null take up more space?

(system) #6