elastic search giving wrong results

236 Views Asked by At

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

0

There are 0 best solutions below