I use Java and Java High Level REST Client.
I need to build query that will find documents. This query should contain many fields for searching.
For example, I have such json:
and I need find all documents due to the all fields.
I understand how constract query due to the one field (parametr) but don't know how I can use a lot of fields for query:
@PostMapping("/findMetricsByValues") @Transactional
public ResponseEntity findMetricsByValues(@RequestBody ElasticSearchMetrics metrics){
And I have one more question.
What if some of this fields will have null value. For example, in my case "timeStamp" and "system" will be empty, but I want get all document due to the fields that won't have null value be in json:
I just want to get result(records) of existing metrics when one or a few of the fields will be NULL and other fields will exist in ES.
But when one of the fields will be incorrect (there no such records in ES) than I won't get any result (records).
SearchRequest searchRequest = new SearchRequest();
SearchSourceBuilder sourceBuilder = new SearchSourceBuilder();
sourceBuilder.query(QueryBuilders.boolQuery()
.should(QueryBuilders.termQuery("value", metrics.getValue()))
.should(QueryBuilders.termQuery("type", metrics.getType()))
.should(QueryBuilders.termQuery("system", metrics.getSystem()))
);
searchRequest.source(sourceBuilder);
In such way when one of the fields will be NULL, ES will find records according to other fields even if one of the fields will be inccorrect (there not such record in ES). But I need when one of the fields won't exsist in ES, but not NULL, then I don't get any result.
Could you provide a full recreation script as described in About the Elasticsearch category. It will help to better understand what you want to do exactly. Please, try to keep the example as simple as possible (like one or two fields should be enough).
I can't reproduce with that. Please read carefully About the Elasticsearch category. There is an example of what is a recreation script.
Here I can't just copy and paste and run.
Can I add in this query condition: if meaning of "value" will be NULL then just don't execute this term ? In other case just execute the term with other terms.
Apache, Apache Lucene, Apache Hadoop, Hadoop, HDFS and the yellow elephant
logo are trademarks of the
Apache Software Foundation
in the United States and/or other countries.