I am using elasticsearch (6.2.1) in my project. The indexing queries are running fine. Whereas the searching query is not working. It works with curl and give search results. But when using java search api, it always give 0 hits including for "match_all" query.
The Java code is given below:
RestClientBuilder builder = RestClient.builder(
new HttpHost("localhost", 9200, "http"));
builder.setMaxRetryTimeoutMillis(60*1000);
RestHighLevelClient client = new RestHighLevelClient(builder);
SearchSourceBuilder sourceBuilder = new SearchSourceBuilder();
sourceBuilder .query(QueryBuilders.queryStringQuery(queryString));
sourceBuilder .timeout(new TimeValue(60, TimeUnit.SECONDS));**
SearchRequest searchRequest = new SearchRequest();
searchRequest.source(sourceBuilder );
SearchResponse searchResponse = client.search(searchRequest);
SearchHits hits = searchResponse.getHits();
The query that generated is:
{"timeout":"60s","query":{"query_string":{"query":"(name:John)","fields":[],"type":"best_fields","default_operator":"or","max_determinized_states":10000,"enable_position_increments":true,"fuzziness":"AUTO","fuzzy_prefix_length":0,"fuzzy_max_expansions":50,"phrase_slop":0,"escape":false,"auto_generate_synonyms_phrase_query":true,"fuzzy_transpositions":true,"boost":1.0}}}
Doc that I expect to match:
"_index": "registration_forms_index",
"_type": "doc",
"_id": "9J_k72MBX-yYREG15tOQ",
"_score": 1,
"_source": {
"{"reg_no":31,"name":"John","datafilePath":"C:\repo_master\registration_forms\registration_forms_folder\json.txt"}": "JSON"
}
}