# Java HighLevelRestClient search problem

**URL:** <https://discuss.elastic.co/t/java-highlevelrestclient-search-problem/126264>\
**Category:** Elasticsearch\
**Created:** [March 30, 2018, 6:12pm UTC](https://discuss.elastic.co/t/java-highlevelrestclient-search-problem/126264 "2018-03-30T18:12:00Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![danfisk](https://avatars.discourse-cdn.com/v4/letter/d/85f322/32.png) [@danfisk](https://discuss.elastic.co/u/danfisk)\
**Post date:** [March 30, 2018, 6:12pm UTC](https://discuss.elastic.co/t/java-highlevelrestclient-search-problem/126264/1 "2018-03-30T18:12:00Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [March 30, 2018, 6:50pm UTC](https://discuss.elastic.co/t/java-highlevelrestclient-search-problem/126264/2 "2018-03-30T18:50:11Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![danfisk](https://avatars.discourse-cdn.com/v4/letter/d/85f322/32.png) [@danfisk](https://discuss.elastic.co/u/danfisk)\
**Post date:** [April 2, 2018, 1:31pm UTC](https://discuss.elastic.co/t/java-highlevelrestclient-search-problem/126264/3 "2018-04-02T13:31:32Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [April 2, 2018, 3:25pm UTC](https://discuss.elastic.co/t/java-highlevelrestclient-search-problem/126264/4 "2018-04-02T15:25:52Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![danfisk](https://avatars.discourse-cdn.com/v4/letter/d/85f322/32.png) [@danfisk](https://discuss.elastic.co/u/danfisk)\
**Post date:** [April 2, 2018, 4:38pm UTC](https://discuss.elastic.co/t/java-highlevelrestclient-search-problem/126264/5 "2018-04-02T16:38:58Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![danfisk](https://avatars.discourse-cdn.com/v4/letter/d/85f322/32.png) [@danfisk](https://discuss.elastic.co/u/danfisk)\
**Post date:** [April 2, 2018, 5:25pm UTC](https://discuss.elastic.co/t/java-highlevelrestclient-search-problem/126264/6 "2018-04-02T17:25:36Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [April 2, 2018, 5:27pm UTC](https://discuss.elastic.co/t/java-highlevelrestclient-search-problem/126264/7 "2018-04-02T17:27:16Z")

</div>

Worth opening an issue then and link to this thread?

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [April 30, 2018, 5:27pm UTC](https://discuss.elastic.co/t/java-highlevelrestclient-search-problem/126264/8 "2018-04-30T17:27:17Z")

</div>

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