Java HighLevelRestClient search problem

I am new to ElasticSearch and have been trying to write Java EE to bring data in from an Informal DB and then run user searches on it. I have been able to get the indexing to work and am able to retrieve a specific indexed document via 'GET /index/type/id' type structure, but when I try to search for a string I get various errors. Currently, I am running on a local instance of ElasticSearch ver6.0.0 on my MacBook Pro. I also have a local instance of Kibana running and am able to retrieve data within it.

My code looks like this:

  public SearchResponse searchRecord(String searchString ) throws RadarException {
        
        SearchRequest searchRequest = new SearchRequest(); 
        SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder(); 
        searchSourceBuilder.query(QueryBuilders.queryStringQuery(searchString)
                                                    .lenient(Boolean.TRUE)
                                                    .autoGenerateSynonymsPhraseQuery(Boolean.FALSE)); 
        searchRequest.source(searchSourceBuilder); 
        searchRequest.types("njcrash");   //put in to see if specifying a type would fix error when type was not specifed

        SearchResponse searchResponse;
        
        try {
            searchResponse = restClient.search(searchRequest);

        } catch (Throwable t) {
            throw new RadarException("Search faild: " + searchRequest.source().toString(), t);
        }

I get the following error (just a segment from the stack dump):

 [type=parsing_exception, reason=[query_string] query does not support [auto_generate_synonyms_phrase_query]]]

The following is the generated search string that was executed ('searchRequest.source()'):

{"query":{"query_string":{"query":"JULIE","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,"lenient":true,"escape":false,"auto_generate_synonyms_phrase_query":false,"fuzzy_transpositions":true,"boost":1.0}}}

My problem/question is .. How do I get the QueryBuilders.queryStringQuery(string) to STOP inserting the 'auto_generate_sysnonyms_phrase_query' parameter since query_string doesn't support it?

Oh, I just noticed the code segment was from after I tried making the auto_generate_synonyms_phrase_query false... prior to this the parameter was NOT present in the code and it added it anyways set to TRUE.
Dan

Most likely you are using a version of the HLRestClient which os totally different from the server. Like HLClient 5 with Server 6 or HLClient 6 with server 5.

1 Like

Hi, Hope you had a good holiday weekend..

I have checked my code and have brought in the 6.2.2 High Level client:
compile 'org.elasticsearch.client:elasticsearch-rest-high-level-client:6.2.2'
and
compile 'org.elasticsearch.client:elasticsearch-rest-client:6.2.2'

and the server was the 6.0.0 build:
elasticsearch-6.0.0.tar

The server is supposed to be forward compatible, right?

This should work. I'd use that same server version though

Okay.. I have downloaded the latest 6.2.3 server and High Level and Low level clients 6.2.3..

Removed the .autoGenerateSynonymsPhraseQuery parameter from the search builder as shown below:

public SearchResponse searchRecord(String searchString ) throws RadarException {

SearchRequest searchRequest = new SearchRequest(); 
SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder(); 
searchSourceBuilder.query(QueryBuilders.queryStringQuery(searchString)
                                            .lenient(Boolean.TRUE));
                                     //       .autoGenerateSynonymsPhraseQuery(Boolean.FALSE)); 
searchRequest.source(searchSourceBuilder); 
searchRequest.types("njcrash");   //put in to see if specifying a type would fix error when type was not specifed

SearchResponse searchResponse;

try {
    searchResponse = restClient.search(searchRequest);

} catch (Throwable t) {
    throw new RadarException("Search faild: " + searchRequest.source().toString(), t);
}

return searchResponse;

}

and yet it still adds it into the built search command..

...Exception: Search faild: {"query":{"query_string":{"query":"JULIE","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,"lenient":true,"escape":false,"auto_generate_synonyms_phrase_query":true,"fuzzy_transpositions":true,"boost":1.0}}}

Any other ideas?

OK, found it... I would call it a bug, but maybe I don't understand something... If you comment out the statement in the above code segment:
searchRequest.types("njcrash");

Then it does not add the auto_generate_synonyms_phrase_query to the searchRequest. It seems like you should be able to restrict the search to only a certain type with this parameter but maybe that is done another way.

Worth opening an issue then and link to this thread?

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.