logger is the ESLogger, but you can swap any IO writer you want

If you converted your example code to using the non deprecated java APIs, 
you'd end up with something like:

String script = "_score * (doc['po'].empty ? 1 : doc['po'].value == 0.0 ? 1 
: doc['po'].value)";
FunctionScoreQueryBuilder fsq = QueryBuilders.functionScoreQuery(
    QueryBuilders.queryString("foo").field("text", 
30).field("ad").field("st").field("cn").field("co").defaultOperator(Operator.AND),
 
ScoreFunctionBuilders.scriptFunction(script));

SearchRequestBuilder srb = new SearchRequestBuilder(client);
...set type, etc. 
srb.setExplain(true);
srb.setQuery(fsq.buildAsBytes());
logger.info("dsl: {}", srb.toString());


Which is roughly equivalent to:


curl -XGET 'localhost:9200/yourindex/yourtype/_search' -d '{
  "query": {
    "function_score": {
      "query": {
        "query_string": {
          "query": "john",
          "fields": [
            "text^30.0",
            "ad",
            "st",
            "cn",
            "co"
          ],
          "default_operator": "and"
        }
      },
      "script_score": {
        "script": "_score * (doc['po'].empty ? 1 : doc['po'].value == 0.0 ? 
1 : doc['po'].value)"
      }
    }
  }
}'



On Friday, January 31, 2014 2:45:39 PM UTC-5, seallison wrote:
>
> With the Java API I'm pretty sure you can get the query DSL from the 
> toString() on SearchRequestBuilder.
>
> Something like this might work for you:
>
> SearchRequestBuilder searchRequestBuilder = new 
> SearchRequestBuilder(client);
>
> ...
>
> searchRequestBuilder.setQuery(queryBuilder.buildAsBytes());
>
> logger.info("query: {}", searchRequestBuilder);
> HTH
>
> On Friday, January 31, 2014 2:12:22 PM UTC-5, coder wrote:
>>
>> Hi,
>>
>> I have following java code which query for search results.
>>
>> String script = "_score * (doc['po'].empty ? 1 : doc['po'].value == 0.0 ? 
>> 1 : doc['po'].value)";
>>         QueryBuilder queryBuilder = QueryBuilders.customScoreQuery(
>> QueryBuilders.queryString(query)
>>                                             .field("text",30)
>>                                             .field("ad")
>>                                             .field("st")
>>                                             .field("cn")
>>                                             .field("co")
>>                                             
>> .defaultOperator(Operator.AND)).script(script);
>>
>> Can anyone tell me what will be the equivalent query dsl along with the 
>> explain api ?
>>
>> I tried using this but it is not working:
>>
>> curl -XGET localhost:9200/acqindex/_search&pretty=true&explain=true -d '{
>>         "query":{
>>                 "custom_score": {
>>                         "query": {      
>>                                         "query": "hotel in"
>>                         },
>>                         "script" : "_score * doc['po'].value"
>>                 }
>>         }
>> }'
>>
>> Thanks
>>
>>
>>
>>

-- 
You received this message because you are subscribed to the Google Groups 
"elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to elasticsearch+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/elasticsearch/1a8462a6-59cc-4ae3-97e7-e51ef8ec719d%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to