Under an index, I have my documents with fields lets say name and location.
Now, to search all documents with name "Peter" and location "Paris".
My Java code for this is:
SearchRequest searchRequest = new SearchRequest(indexName);
SearchSourceBuilder builder = new SearchSourceBuilder().postFilter(QueryBuilders.termQuery("name", "Peter")).postFilter(QueryBuilders.termQuery("location", "Paris"));
SearchResponse response = null;
try {
response = client.search(searchRequest, RequestOptions.DEFAULT);
} catch (IOException e) {
e.printStackTrace();
}
Above code, doesn't give me accurate result. Could someone please help with correct approach ?