Need some help on to query ES using java Transport client. I need to apply few filter conditions and also select only few fields from the ES.
Example: Let's say, I have many fields in the documents as below and I have @timestamp which is also a field in the response { .............., @timestamp=Fri Jul 07 01:36:00 IST 2017, ..............}, Here how can I get the only field @timestamp from all the documents for my index ? and also how can I apply filter on this Timestamp field ?
Here how can I get the only field @timestamp from all the documents for my index ?
If in the mapping you explicitly stored the @timestamp field, then you can run a Search Request and set the storedField to get as @timestamp instead of _source (default).
I am new to ES, and I have written some code as below:
SearchResponse response = client.prepareSearch(searchIndex + "*").storedFields("@timestamp")
.setScroll(new TimeValue(6000))
.setSize(100).get();
// max of 100 hits will be returned for each scroll
// Scroll until no hits are returned
do {
for (SearchHit searchHit : response.getHits().getHits()) {
// Handle the hit...
get response= searchHit.getSource();
}
response = client.prepareSearchScroll(response.getScrollId())
.setScroll(new TimeValue(3600))
.execute().actionGet();
} while (response.getHits().getHits().length != 0);
}
Now as I explained earlier I need to add the code to apply fielter based on @timestamp field and select only @timestamp here. Could you please help ?
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.