The Coalesce field expression will return the first non-null child field expression. The data type for the returned field will be the "most lenient" data type over all supplied field expressions. Data type "leniency" is (from least to most): boolean -> int -> long -> float -> double -> string. If DATE or POINT data types are used with any other type, a String field will be returned. This expression is very useful for creating "fallback" fields in the event that a field is not populated.
QueryRequest request = new QueryRequest("*:*"); // Request the "title" field, fallback to the "description" field if title is not available // The returned field will be named "title" request.addField( new Coalesce(new StoredField("title"), new StoredField("description")).as("title") ); // ... (Perform the search)
COALESCE(FIELDEXPRESSION, FIELDEXPRESSION, ...)
- FIELDEXPRESSION- any legal field expression.
- The first field expression specified that has a non-null value will be the value returned for this expression.
&fields=COALESCE(title, description) AS title