1

I'm new to elastic search and trying to fetch logs from it using java and I've noticed that it gives me wrong results at times. Below is the piece of code:

String connectionUrl = "https://elasticsrchurl.eu-west-1.es.amazonaws.com";
JestClientFactory factory = new JestClientFactory();
factory.setHttpClientConfig(new HttpClientConfig
           .Builder(connectionUrl)
           .multiThreaded(true)
           .build());
JestHttpClient client = (JestHttpClient)factory.getObject();

SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();
searchSourceBuilder.query(QueryBuilders.matchQuery("Name", 
"John"));
searchSourceBuilder.size(1);

Search search = (Search) new Search.Builder( searchSourceBuilder.toString())
.addIndex("index name")
.build();
try {
JestResult result = client.execute(search);
}catch (Exception e){}

Do I need to use something else other than matchQuery? Is this the correct way of searching it or I should use Query string?

We are using elastic search to store logs and every day thousand of logs gets created but all with a unique id. I'm searching on the basis of that unique id but it at times fetches the wrong result.

Edit

I managed to get the correct result right by changing the index and adding a wait of 2 minutes in my code, but it still returns some vague results with the correct one. Is there any way I can limit my search result only to the exact match?

Regards, Sunil Ojha

Nkosi
  • 235,767
  • 35
  • 427
  • 472
Sunil Ojha
  • 223
  • 1
  • 7
  • 20
  • 1
    Your code creates a http request. If you put the http request information rather than the Java code to create the request, you'll be able to get assistance from a wider audience. – Daryl Van Sittert Nov 30 '17 at 08:36
  • @Sunil cold you try to reproduce using curl? – Mangat Rai Modi Nov 30 '17 at 09:08
  • @Mangat I've not yet tried with curl but I'll try and let you know. Also, is there a method that if the log doesn't exist then it returns nothing instead of returning wrong results? – Sunil Ojha Nov 30 '17 at 09:20

0 Answers0