1

I am using the below search query:

{ "from": "0", "size": "20", "query": {"query_string" : {"fields" : ["title"],"query" : "seller*", "analyze_wildcard": true}}}

This curl hit returns me hits/results with proper score, whereas I am trying same thru the elasticsearch transport client like:

String queryString = "{" 
           + "\"query_string\" : {\n" + 
           "       \"fields\" : [\"title\"],\n" + 
           "       \"query\" : "+ "\"" + searchQuery  + "\",\n" + 
           "       \"analyze_wildcard\": true \n" + 
           "   }}\n";

SearchResponse response2 = client.prepareSearch(indexName).setTypes(successZoneTypeName).setFrom(0).setSize(30).setQuery(QueryBuilders.queryStringQuery(queryString)).get();

This returns the result with same score against all the hits.

Even I tried with jest client the result is same I am not getting proper scores in the result.

Nkosi
  • 235,767
  • 35
  • 427
  • 472
abhineet
  • 195
  • 1
  • 1
  • 11

1 Answers1

2

This is not the proper way of constructing a query string query via Java. You should do it this way:

QueryBuilder qs = QueryBuilders.queryStringQuery("\"" + searchQuery  + "\"")
   .field("title")
   .analyzeWildcard(true);

SearchResponse response2 = client.prepareSearch(indexName)
   .setTypes(successZoneTypeName)
   .setFrom(0)
   .setSize(30)
   .setQuery(qs)
   .get();
Val
  • 207,596
  • 13
  • 358
  • 360
  • Why is that if the searchQuery is concatenated with asterisk '*' in case of wildcard search, the score for all the records come as 1? – abhineet Jun 16 '16 at 06:24
  • You should probably ask a new question as it would benefit other SO readers as well. – Val Jun 16 '16 at 06:32
  • As you suggested I have created a separate question for that [link](http://stackoverflow.com/questions/37875057/why-is-that-if-the-search-string-is-concatenated-with-asterisk-in-case-of-wi) Also, I realized that even in this question I was getting the same score i.e. 1 because of '*' otherwise it works fine. – abhineet Jun 17 '16 at 07:01