stefansaye stefansaye - 1 year ago 165
Java Question

Elasticsearch using Java api

Hi I am trying to do query on elastic search by following the sql query and I want to implement same logic using Java API

select * from log , web where l.loghost = w.webhost and @datetime between '2016-05-20' AND '2016-05-25'

are different types, and indices are set to
format looks like

Now I have the following Java code but i don't know how to set between two dates ,so it does not return expected output

SearchResponse response = client.prepareSearch("logstash-log-*","logstash-web-*")
.setFetchSource(new String[]{"*"}, null)
.setQuery(QueryBuilders.queryStringQuery("").field("*_host"))// Query

Please guide I am new to Elastic search. Thanks in advance.

Val Val
Answer Source

You need to combine a range query with your query_string query inside a bool/filter query:

QueryStringQueryBuilder qs = QueryBuilders.queryStringQuery("").field("*_host");
RangeQueryBuilder range = QueryBuilders.rangeQuery("@timestamp")

and then

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download