# What will be the equivalent query of the following java api?

**URL:** <https://discuss.elastic.co/t/what-will-be-the-equivalent-query-of-the-following-java-api/15536>\
**Category:** Elasticsearch\
**Created:** [January 31, 2014, 7:12pm UTC](https://discuss.elastic.co/t/what-will-be-the-equivalent-query-of-the-following-java-api/15536 "2014-01-31T19:12:22Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![dark\_shadow](https://avatars.discourse-cdn.com/v4/letter/d/4af34b/32.png) [@dark\_shadow](https://discuss.elastic.co/u/dark_shadow)\
**Post date:** [January 31, 2014, 7:12pm UTC](https://discuss.elastic.co/t/what-will-be-the-equivalent-query-of-the-following-java-api/15536/1 "2014-01-31T19:12:22Z")

</div>

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+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/55d56cf3-89f3-4e25-b72a-7812ad7d764d%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/55d56cf3-89f3-4e25-b72a-7812ad7d764d%40googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![seallison](https://avatars.discourse-cdn.com/v4/letter/s/4af34b/32.png) [@seallison](https://discuss.elastic.co/u/seallison)\
**Post date:** [January 31, 2014, 7:45pm UTC](https://discuss.elastic.co/t/what-will-be-the-equivalent-query-of-the-following-java-api/15536/2 "2014-01-31T19:45:39Z")

</div>

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+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/b68af0ce-c964-41b7-ae17-0c82b17271d4%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/b68af0ce-c964-41b7-ae17-0c82b17271d4%40googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![dark\_shadow](https://avatars.discourse-cdn.com/v4/letter/d/4af34b/32.png) [@dark\_shadow](https://discuss.elastic.co/u/dark_shadow)\
**Post date:** [January 31, 2014, 7:48pm UTC](https://discuss.elastic.co/t/what-will-be-the-equivalent-query-of-the-following-java-api/15536/3 "2014-01-31T19:48:56Z")

</div>

What is logger.info ? Can you please help me in writing the query dsl  
itself. I tried writing it but failed ☹

On Sat, Feb 1, 2014 at 1:15 AM, seallison [seallison@gmail.com](mailto:seallison@gmail.com) 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+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
> > To view this discussion on the web visit  
> > [https://groups.google.com/d/msgid/elasticsearch/b68af0ce-c964-41b7-ae17-0c82b17271d4%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/b68af0ce-c964-41b7-ae17-0c82b17271d4%40googlegroups.com)  
> > .
> 
> For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

--  
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+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/CAAVTvp5Gte-phT%2Bt%2B3qG4ErxGu%2BXP24vCT5C6sasg9q%3D%3DvM3ZQ%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CAAVTvp5Gte-phT%2Bt%2B3qG4ErxGu%2BXP24vCT5C6sasg9q%3D%3DvM3ZQ%40mail.gmail.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![Binh\_Ly](https://avatars.discourse-cdn.com/v4/letter/b/ce7236/32.png) [@Binh\_Ly](https://discuss.elastic.co/u/Binh_Ly)\
**Post date:** [January 31, 2014, 8:17pm UTC](https://discuss.elastic.co/t/what-will-be-the-equivalent-query-of-the-following-java-api/15536/4 "2014-01-31T20:17:42Z")

</div>

Should be roughly like this:

{  
"query": {  
"custom\_score": {  
"query": {  
"query\_string": {  
"query": "blah blah",  
"fields": [  
"text^30",  
"ad",  
"st",  
"cn",  
"co"  
],  
"default\_operator": "AND"  
}  
},  
"script": "\_score \* (doc['po'].empty ? 1 : doc['po'].value == 0.0 ? 1  
: doc['po'].value)"  
}  
}  
}

--  
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+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/07ae02b5-39d9-410d-892e-8ff366de515c%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/07ae02b5-39d9-410d-892e-8ff366de515c%40googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![dark\_shadow](https://avatars.discourse-cdn.com/v4/letter/d/4af34b/32.png) [@dark\_shadow](https://discuss.elastic.co/u/dark_shadow)\
**Post date:** [January 31, 2014, 8:39pm UTC](https://discuss.elastic.co/t/what-will-be-the-equivalent-query-of-the-following-java-api/15536/5 "2014-01-31T20:39:19Z")

</div>

Binh,

how can I add explain:true in that one ?

On Sat, Feb 1, 2014 at 1:47 AM, Binh Ly [binh@hibalo.com](mailto:binh@hibalo.com) wrote:

> Should be roughly like this:
> 
> {  
> "query": {  
> "custom\_score": {  
> "query": {  
> "query\_string": {  
> "query": "blah blah",  
> "fields": [  
> "text^30",  
> "ad",  
> "st",  
> "cn",  
> "co"  
> ],  
> "default\_operator": "AND"  
> }  
> },  
> "script": "\_score \* (doc['po'].empty ? 1 : doc['po'].value == 0.0 ?  
> 1 : doc['po'].value)"  
> }  
> }  
> }
> 
> --  
> 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+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
> To view this discussion on the web visit  
> [https://groups.google.com/d/msgid/elasticsearch/07ae02b5-39d9-410d-892e-8ff366de515c%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/07ae02b5-39d9-410d-892e-8ff366de515c%40googlegroups.com)  
> .
> 
> For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

--  
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+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/CAAVTvp4tYv6S2otq3iGX6ssRg4p3QZPRUePJhZjLEyvQ84%3DMAg%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CAAVTvp4tYv6S2otq3iGX6ssRg4p3QZPRUePJhZjLEyvQ84%3DMAg%40mail.gmail.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![dark\_shadow](https://avatars.discourse-cdn.com/v4/letter/d/4af34b/32.png) [@dark\_shadow](https://discuss.elastic.co/u/dark_shadow)\
**Post date:** [January 31, 2014, 8:49pm UTC](https://discuss.elastic.co/t/what-will-be-the-equivalent-query-of-the-following-java-api/15536/6 "2014-01-31T20:49:57Z")

</div>

Binh,

I'm getting \_score as 1 by replicating the above query.

curl -XPUT '[http://localhost:9200/acqindex/](http://localhost:9200/acqindex/)' -d '{  
"settings" : {  
"index" : {  
"number\_of\_shards" : 1,  
"number\_of\_replicas" : 1,  
"analysis" : {  
"analyzer" : {  
"str\_search\_analyzer" : {  
"tokenizer" : "standard",  
"filter" :  
["lowercase","asciifolding","suggestions\_shingle","edgengram"]  
},  
"str\_index\_analyzer" : {  
"tokenizer" : "standard",  
"filter" :  
["lowercase","asciifolding","suggestions\_shingle","edgengram"]  
}  
},  
"filter" : {  
"suggestions\_shingle": {  
"type": "shingle",  
"min\_shingle\_size": 2,  
"max\_shingle\_size": 5  
},  
"edgengram" : {  
"type" : "edgeNGram",  
"min\_gram" : 2,  
"max\_gram" : 30,  
"side" : "front"  
},  
"Length" : {  
"type" : "length",  
"min" : 3  
}  
}  
}  
}  
}  
}'

curl -XPUT 'localhost:9200/acqindex/acqidx/\_mapping' -d'{  
"acqidx":{  
"\_boost": {  
"name":"boostFactor",  
"null\_value":3.0  
},  
"properties":{  
"text":{"type":"string",  
"search\_analyzer" : "str\_search\_analyzer",  
"index\_analyzer":"str\_index\_analyzer"  
},  
"po": {  
"type": "double",  
"boost": 4.0  
},  
"boostFactor": {  
"type": "double"  
}  
}  
}  
}'

curl -XPUT 'localhost:9200/acqindex/acqidx/1' -d '{ text:"Hotels in  
Hoscur",po:8.8,boostFactor:8.8 }',  
curl -XPUT 'localhost:9200/acqindex/acqidx/2' -d '{ text:"Hotels in  
innsburg",po:8.9,boostFactor:8.9 }'  
curl -XPUT 'localhost:9200/acqindex/acqidx/5' -d '{ text:"Hotels in  
delhi",po:9.0,boostFactor:9.0 }'  
curl -XPUT 'localhost:9200/acqindex/acqidx/3' -d '{ text:"Hotels in  
ink",po:9.0001,boostFactor:9.0001 }'  
curl -XPUT 'localhost:9200/acqindex/acqidx/4' -d '{ text:"Hotels in  
houston",po:9.0002,boostFactor:9.0002 }'  
curl -XPUT 'localhost:9200/acqindex/acqidx/6' -d '{ text:"Hotels in  
darjeling",po:9.0001,boostFactor:9.0001 }'

curl -XGET localhost:9200/acqindex/\_search&pretty=true&explain=true -d '{  
"query":{  
"custom\_score": {  
"query": {  
"query\_string" : {  
"query": "hotel in",  
"fields":["text^30"]  
}  
},  
"script" : "\_score \* doc['po'].value"  
}  
}  
}'

Any idea why is such a behaviour is observed. I know \_boost should have  
different parameter that's why using a different parameter. As you told  
earlier if I want to use my "po" field in custom score query, I'll have to  
remove that \_boost segment. But I need \_boost so that I can add document  
boost to my docs. That's why checking with a small use case.

Please help !!!

Thanks

On Sat, Feb 1, 2014 at 2:09 AM, Mukul Gupta [mukulnitkkr@gmail.com](mailto:mukulnitkkr@gmail.com) wrote:

> Binh,
> 
> how can I add explain:true in that one ?
> 
> On Sat, Feb 1, 2014 at 1:47 AM, Binh Ly [binh@hibalo.com](mailto:binh@hibalo.com) wrote:
> 
> > Should be roughly like this:
> > 
> > {  
> > "query": {  
> > "custom\_score": {  
> > "query": {  
> > "query\_string": {  
> > "query": "blah blah",  
> > "fields": [  
> > "text^30",  
> > "ad",  
> > "st",  
> > "cn",  
> > "co"  
> > ],  
> > "default\_operator": "AND"  
> > }  
> > },  
> > "script": "\_score \* (doc['po'].empty ? 1 : doc['po'].value == 0.0 ?  
> > 1 : doc['po'].value)"  
> > }  
> > }  
> > }
> > 
> > --  
> > 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+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
> > To view this discussion on the web visit  
> > [https://groups.google.com/d/msgid/elasticsearch/07ae02b5-39d9-410d-892e-8ff366de515c%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/07ae02b5-39d9-410d-892e-8ff366de515c%40googlegroups.com)  
> > .
> > 
> > For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

--  
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+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/CAAVTvp6anHtDAnj2AkkbADUEqDt7J7\_5XWQPJp6xP9t9G1F0ng%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CAAVTvp6anHtDAnj2AkkbADUEqDt7J7_5XWQPJp6xP9t9G1F0ng%40mail.gmail.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![Ivan](https://avatars.discourse-cdn.com/v4/letter/i/df788c/32.png) [@Ivan](https://discuss.elastic.co/u/Ivan)\
**Post date:** [January 31, 2014, 8:57pm UTC](https://discuss.elastic.co/t/what-will-be-the-equivalent-query-of-the-following-java-api/15536/7 "2014-01-31T20:57:39Z")

</div>

Not sure what behavior you are observing since you did not add any results.  
One thing however is you are essentially boosting everything twice. Once  
with a document boost and then again with the custom score. Remove the  
document boost.

--  
Ivan

On Fri, Jan 31, 2014 at 12:49 PM, Mukul Gupta [mukulnitkkr@gmail.com](mailto:mukulnitkkr@gmail.com) wrote:

> Binh,
> 
> I'm getting \_score as 1 by replicating the above query.
> 
> curl -XPUT '[http://localhost:9200/acqindex/](http://localhost:9200/acqindex/)' -d '{  
> "settings" : {  
> "index" : {  
> "number\_of\_shards" : 1,  
> "number\_of\_replicas" : 1,  
> "analysis" : {  
> "analyzer" : {  
> "str\_search\_analyzer" : {  
> "tokenizer" : "standard",  
> "filter" :  
> ["lowercase","asciifolding","suggestions\_shingle","edgengram"]  
> },  
> "str\_index\_analyzer" : {  
> "tokenizer" : "standard",  
> "filter" :  
> ["lowercase","asciifolding","suggestions\_shingle","edgengram"]  
> }  
> },  
> "filter" : {  
> "suggestions\_shingle": {  
> "type": "shingle",  
> "min\_shingle\_size": 2,  
> "max\_shingle\_size": 5  
> },  
> "edgengram" : {  
> "type" : "edgeNGram",  
> "min\_gram" : 2,  
> "max\_gram" : 30,  
> "side" : "front"  
> },  
> "Length" : {  
> "type" : "length",  
> "min" : 3  
> }  
> }  
> }  
> }  
> }  
> }'
> 
> curl -XPUT 'localhost:9200/acqindex/acqidx/\_mapping' -d'{  
> "acqidx":{  
> "\_boost": {  
> "name":"boostFactor",  
> "null\_value":3.0  
> },  
> "properties":{  
> "text":{"type":"string",  
> "search\_analyzer" : "str\_search\_analyzer",  
> "index\_analyzer":"str\_index\_analyzer"  
> },  
> "po": {  
> "type": "double",  
> "boost": 4.0  
> },  
> "boostFactor": {  
> "type": "double"  
> }  
> }  
> }  
> }'
> 
> curl -XPUT 'localhost:9200/acqindex/acqidx/1' -d '{ text:"Hotels in  
> Hoscur",po:8.8,boostFactor:8.8 }',  
> curl -XPUT 'localhost:9200/acqindex/acqidx/2' -d '{ text:"Hotels in  
> innsburg",po:8.9,boostFactor:8.9 }'  
> curl -XPUT 'localhost:9200/acqindex/acqidx/5' -d '{ text:"Hotels in  
> delhi",po:9.0,boostFactor:9.0 }'  
> curl -XPUT 'localhost:9200/acqindex/acqidx/3' -d '{ text:"Hotels in  
> ink",po:9.0001,boostFactor:9.0001 }'  
> curl -XPUT 'localhost:9200/acqindex/acqidx/4' -d '{ text:"Hotels in  
> houston",po:9.0002,boostFactor:9.0002 }'  
> curl -XPUT 'localhost:9200/acqindex/acqidx/6' -d '{ text:"Hotels in  
> darjeling",po:9.0001,boostFactor:9.0001 }'
> 
> curl -XGET localhost:9200/acqindex/\_search&pretty=true&explain=true -d '{  
> "query":{  
> "custom\_score": {  
> "query": {  
> "query\_string" : {  
> "query": "hotel in",  
> "fields":["text^30"]
> 
> ```
> }
> },
> "script" : "_score * doc['po'].value"
> }
> }
> 
> ```
> 
> }'
> 
> Any idea why is such a behaviour is observed. I know \_boost should have  
> different parameter that's why using a different parameter. As you told  
> earlier if I want to use my "po" field in custom score query, I'll have to  
> remove that \_boost segment. But I need \_boost so that I can add document  
> boost to my docs. That's why checking with a small use case.
> 
> Please help !!!
> 
> Thanks
> 
> On Sat, Feb 1, 2014 at 2:09 AM, Mukul Gupta [mukulnitkkr@gmail.com](mailto:mukulnitkkr@gmail.com) wrote:
> 
> > Binh,
> > 
> > how can I add explain:true in that one ?
> > 
> > On Sat, Feb 1, 2014 at 1:47 AM, Binh Ly [binh@hibalo.com](mailto:binh@hibalo.com) wrote:
> > 
> > > Should be roughly like this:
> > > 
> > > {  
> > > "query": {  
> > > "custom\_score": {  
> > > "query": {  
> > > "query\_string": {  
> > > "query": "blah blah",  
> > > "fields": [  
> > > "text^30",  
> > > "ad",  
> > > "st",  
> > > "cn",  
> > > "co"  
> > > ],  
> > > "default\_operator": "AND"  
> > > }  
> > > },  
> > > "script": "\_score \* (doc['po'].empty ? 1 : doc['po'].value == 0.0  
> > > ? 1 : doc['po'].value)"  
> > > }  
> > > }  
> > > }
> > > 
> > > --  
> > > 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+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
> > > To view this discussion on the web visit  
> > > [https://groups.google.com/d/msgid/elasticsearch/07ae02b5-39d9-410d-892e-8ff366de515c%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/07ae02b5-39d9-410d-892e-8ff366de515c%40googlegroups.com)  
> > > .
> > > 
> > > For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).
> 
> --  
> 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+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
> To view this discussion on the web visit  
> [https://groups.google.com/d/msgid/elasticsearch/CAAVTvp6anHtDAnj2AkkbADUEqDt7J7\_5XWQPJp6xP9t9G1F0ng%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CAAVTvp6anHtDAnj2AkkbADUEqDt7J7_5XWQPJp6xP9t9G1F0ng%40mail.gmail.com)  
> .
> 
> For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

--  
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+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/CALY%3DcQA6swutEJJFZbUTHkmyYTiaR\_szL%3DLFEDXakstf%3DtCeWg%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CALY%3DcQA6swutEJJFZbUTHkmyYTiaR_szL%3DLFEDXakstf%3DtCeWg%40mail.gmail.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![dark\_shadow](https://avatars.discourse-cdn.com/v4/letter/d/4af34b/32.png) [@dark\_shadow](https://discuss.elastic.co/u/dark_shadow)\
**Post date:** [January 31, 2014, 9:02pm UTC](https://discuss.elastic.co/t/what-will-be-the-equivalent-query-of-the-following-java-api/15536/8 "2014-01-31T21:02:37Z")

</div>

Actually just want to see if using a different field name for boost and  
another field for script/score actually works as you mentioned in one of  
the earlier posts for Elasticsearch-0.90.3

On Sat, Feb 1, 2014 at 2:27 AM, Ivan Brusic [ivan@brusic.com](mailto:ivan@brusic.com) wrote:

> Not sure what behavior you are observing since you did not add any  
> results. One thing however is you are essentially boosting everything  
> twice. Once with a document boost and then again with the custom score.  
> Remove the document boost.
> 
> --  
> Ivan
> 
> On Fri, Jan 31, 2014 at 12:49 PM, Mukul Gupta [mukulnitkkr@gmail.com](mailto:mukulnitkkr@gmail.com)wrote:
> 
> > Binh,
> > 
> > I'm getting \_score as 1 by replicating the above query.
> > 
> > curl -XPUT '[http://localhost:9200/acqindex/](http://localhost:9200/acqindex/)' -d '{  
> > "settings" : {  
> > "index" : {  
> > "number\_of\_shards" : 1,  
> > "number\_of\_replicas" : 1,  
> > "analysis" : {  
> > "analyzer" : {  
> > "str\_search\_analyzer" : {  
> > "tokenizer" : "standard",  
> > "filter" :  
> > ["lowercase","asciifolding","suggestions\_shingle","edgengram"]  
> > },  
> > "str\_index\_analyzer" : {  
> > "tokenizer" : "standard",  
> > "filter" :  
> > ["lowercase","asciifolding","suggestions\_shingle","edgengram"]  
> > }  
> > },  
> > "filter" : {  
> > "suggestions\_shingle": {  
> > "type": "shingle",  
> > "min\_shingle\_size": 2,  
> > "max\_shingle\_size": 5  
> > },  
> > "edgengram" : {  
> > "type" : "edgeNGram",  
> > "min\_gram" : 2,  
> > "max\_gram" : 30,  
> > "side" : "front"  
> > },  
> > "Length" : {  
> > "type" : "length",  
> > "min" : 3  
> > }  
> > }  
> > }  
> > }  
> > }  
> > }'
> > 
> > curl -XPUT 'localhost:9200/acqindex/acqidx/\_mapping' -d'{  
> > "acqidx":{  
> > "\_boost": {  
> > "name":"boostFactor",  
> > "null\_value":3.0  
> > },  
> > "properties":{  
> > "text":{"type":"string",  
> > "search\_analyzer" : "str\_search\_analyzer",  
> > "index\_analyzer":"str\_index\_analyzer"  
> > },  
> > "po": {  
> > "type": "double",  
> > "boost": 4.0  
> > },  
> > "boostFactor": {  
> > "type": "double"  
> > }  
> > }  
> > }  
> > }'
> > 
> > curl -XPUT 'localhost:9200/acqindex/acqidx/1' -d '{ text:"Hotels in  
> > Hoscur",po:8.8,boostFactor:8.8 }',  
> > curl -XPUT 'localhost:9200/acqindex/acqidx/2' -d '{ text:"Hotels in  
> > innsburg",po:8.9,boostFactor:8.9 }'  
> > curl -XPUT 'localhost:9200/acqindex/acqidx/5' -d '{ text:"Hotels in  
> > delhi",po:9.0,boostFactor:9.0 }'  
> > curl -XPUT 'localhost:9200/acqindex/acqidx/3' -d '{ text:"Hotels in  
> > ink",po:9.0001,boostFactor:9.0001 }'  
> > curl -XPUT 'localhost:9200/acqindex/acqidx/4' -d '{ text:"Hotels in  
> > houston",po:9.0002,boostFactor:9.0002 }'  
> > curl -XPUT 'localhost:9200/acqindex/acqidx/6' -d '{ text:"Hotels in  
> > darjeling",po:9.0001,boostFactor:9.0001 }'
> > 
> > curl -XGET localhost:9200/acqindex/\_search&pretty=true&explain=true -d '{  
> > "query":{  
> > "custom\_score": {  
> > "query": {  
> > "query\_string" : {  
> > "query": "hotel in",  
> > "fields":["text^30"]
> > 
> > ```
> > }
> > },
> > "script" : "_score * doc['po'].value"
> > }
> > }
> > 
> > ```
> > 
> > }'
> > 
> > Any idea why is such a behaviour is observed. I know \_boost should have  
> > different parameter that's why using a different parameter. As you told  
> > earlier if I want to use my "po" field in custom score query, I'll have to  
> > remove that \_boost segment. But I need \_boost so that I can add document  
> > boost to my docs. That's why checking with a small use case.
> > 
> > Please help !!!
> > 
> > Thanks
> > 
> > On Sat, Feb 1, 2014 at 2:09 AM, Mukul Gupta [mukulnitkkr@gmail.com](mailto:mukulnitkkr@gmail.com)wrote:
> > 
> > > Binh,
> > > 
> > > how can I add explain:true in that one ?
> > > 
> > > On Sat, Feb 1, 2014 at 1:47 AM, Binh Ly [binh@hibalo.com](mailto:binh@hibalo.com) wrote:
> > > 
> > > > Should be roughly like this:
> > > > 
> > > > {  
> > > > "query": {  
> > > > "custom\_score": {  
> > > > "query": {  
> > > > "query\_string": {  
> > > > "query": "blah blah",  
> > > > "fields": [  
> > > > "text^30",  
> > > > "ad",  
> > > > "st",  
> > > > "cn",  
> > > > "co"  
> > > > ],  
> > > > "default\_operator": "AND"  
> > > > }  
> > > > },  
> > > > "script": "\_score \* (doc['po'].empty ? 1 : doc['po'].value == 0.0  
> > > > ? 1 : doc['po'].value)"  
> > > > }  
> > > > }  
> > > > }
> > > > 
> > > > --  
> > > > 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+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
> > > > To view this discussion on the web visit  
> > > > [https://groups.google.com/d/msgid/elasticsearch/07ae02b5-39d9-410d-892e-8ff366de515c%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/07ae02b5-39d9-410d-892e-8ff366de515c%40googlegroups.com)  
> > > > .
> > > > 
> > > > For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).
> > 
> > --  
> > 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+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
> > To view this discussion on the web visit  
> > [https://groups.google.com/d/msgid/elasticsearch/CAAVTvp6anHtDAnj2AkkbADUEqDt7J7\_5XWQPJp6xP9t9G1F0ng%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CAAVTvp6anHtDAnj2AkkbADUEqDt7J7_5XWQPJp6xP9t9G1F0ng%40mail.gmail.com)  
> > .
> > 
> > For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).
> 
> --  
> 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+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
> To view this discussion on the web visit  
> [https://groups.google.com/d/msgid/elasticsearch/CALY%3DcQA6swutEJJFZbUTHkmyYTiaR\_szL%3DLFEDXakstf%3DtCeWg%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CALY%3DcQA6swutEJJFZbUTHkmyYTiaR_szL%3DLFEDXakstf%3DtCeWg%40mail.gmail.com)  
> .
> 
> For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

--  
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+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/CAAVTvp4dGscR7eHGvaNvEu341OwVeXVpgc5R8%2BEbt%2BbEYnu3Ow%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CAAVTvp4dGscR7eHGvaNvEu341OwVeXVpgc5R8%2BEbt%2BbEYnu3Ow%40mail.gmail.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![dark\_shadow](https://avatars.discourse-cdn.com/v4/letter/d/4af34b/32.png) [@dark\_shadow](https://discuss.elastic.co/u/dark_shadow)\
**Post date:** [January 31, 2014, 9:04pm UTC](https://discuss.elastic.co/t/what-will-be-the-equivalent-query-of-the-following-java-api/15536/9 "2014-01-31T21:04:09Z")

</div>

Results of the above query:

{"took":1,"timed\_out":false,"\_shards":{"total":1,"successful":1,"failed":0},"hits":{"total":6,"max\_score":1.0,"hits":[{"\_index":"acqindex","\_type":"acqidx","\_id":"1","\_score":1.0,  
"\_source" : { text:"Hotels in Hoscur",po:8.8,boostFactor:8.8  
},},{"\_index":"acqindex","\_type":"acqidx","\_id":"2","\_score":1.0, "\_source"  
: { text:"Hotels in innsburg",po:8.9,boostFactor:8.9  
}},{"\_index":"acqindex","\_type":"acqidx","\_id":"5","\_score":1.0, "\_source"  
: { text:"Hotels in delhi",po:9.0,boostFactor:9.0  
}},{"\_index":"acqindex","\_type":"acqidx","\_id":"3","\_score":1.0, "\_source"  
: { text:"Hotels in ink",po:9.0001,boostFactor:9.0001  
}},{"\_index":"acqindex","\_type":"acqidx","\_id":"4","\_score":1.0, "\_source"  
: { text:"Hotels in houston",po:9.0002,boostFactor:9.0002  
}},{"\_index":"acqindex","\_type":"acqidx","\_id":"6","\_score":1.0, "\_source"  
: { text:"Hotels in darjeling",po:9.0001,boostFactor:9.0001 }}]}}

\_score value is 1 for all of the docs

On Sat, Feb 1, 2014 at 2:27 AM, Ivan Brusic [ivan@brusic.com](mailto:ivan@brusic.com) wrote:

> Not sure what behavior you are observing since you did not add any  
> results. One thing however is you are essentially boosting everything  
> twice. Once with a document boost and then again with the custom score.  
> Remove the document boost.
> 
> --  
> Ivan
> 
> On Fri, Jan 31, 2014 at 12:49 PM, Mukul Gupta [mukulnitkkr@gmail.com](mailto:mukulnitkkr@gmail.com)wrote:
> 
> > Binh,
> > 
> > I'm getting \_score as 1 by replicating the above query.
> > 
> > curl -XPUT '[http://localhost:9200/acqindex/](http://localhost:9200/acqindex/)' -d '{  
> > "settings" : {  
> > "index" : {  
> > "number\_of\_shards" : 1,  
> > "number\_of\_replicas" : 1,  
> > "analysis" : {  
> > "analyzer" : {  
> > "str\_search\_analyzer" : {  
> > "tokenizer" : "standard",  
> > "filter" :  
> > ["lowercase","asciifolding","suggestions\_shingle","edgengram"]  
> > },  
> > "str\_index\_analyzer" : {  
> > "tokenizer" : "standard",  
> > "filter" :  
> > ["lowercase","asciifolding","suggestions\_shingle","edgengram"]  
> > }  
> > },  
> > "filter" : {  
> > "suggestions\_shingle": {  
> > "type": "shingle",  
> > "min\_shingle\_size": 2,  
> > "max\_shingle\_size": 5  
> > },  
> > "edgengram" : {  
> > "type" : "edgeNGram",  
> > "min\_gram" : 2,  
> > "max\_gram" : 30,  
> > "side" : "front"  
> > },  
> > "Length" : {  
> > "type" : "length",  
> > "min" : 3  
> > }  
> > }  
> > }  
> > }  
> > }  
> > }'
> > 
> > curl -XPUT 'localhost:9200/acqindex/acqidx/\_mapping' -d'{  
> > "acqidx":{  
> > "\_boost": {  
> > "name":"boostFactor",  
> > "null\_value":3.0  
> > },  
> > "properties":{  
> > "text":{"type":"string",  
> > "search\_analyzer" : "str\_search\_analyzer",  
> > "index\_analyzer":"str\_index\_analyzer"  
> > },  
> > "po": {  
> > "type": "double",  
> > "boost": 4.0  
> > },  
> > "boostFactor": {  
> > "type": "double"  
> > }  
> > }  
> > }  
> > }'
> > 
> > curl -XPUT 'localhost:9200/acqindex/acqidx/1' -d '{ text:"Hotels in  
> > Hoscur",po:8.8,boostFactor:8.8 }',  
> > curl -XPUT 'localhost:9200/acqindex/acqidx/2' -d '{ text:"Hotels in  
> > innsburg",po:8.9,boostFactor:8.9 }'  
> > curl -XPUT 'localhost:9200/acqindex/acqidx/5' -d '{ text:"Hotels in  
> > delhi",po:9.0,boostFactor:9.0 }'  
> > curl -XPUT 'localhost:9200/acqindex/acqidx/3' -d '{ text:"Hotels in  
> > ink",po:9.0001,boostFactor:9.0001 }'  
> > curl -XPUT 'localhost:9200/acqindex/acqidx/4' -d '{ text:"Hotels in  
> > houston",po:9.0002,boostFactor:9.0002 }'  
> > curl -XPUT 'localhost:9200/acqindex/acqidx/6' -d '{ text:"Hotels in  
> > darjeling",po:9.0001,boostFactor:9.0001 }'
> > 
> > curl -XGET localhost:9200/acqindex/\_search&pretty=true&explain=true -d '{  
> > "query":{  
> > "custom\_score": {  
> > "query": {  
> > "query\_string" : {  
> > "query": "hotel in",  
> > "fields":["text^30"]
> > 
> > ```
> > }
> > },
> > "script" : "_score * doc['po'].value"
> > }
> > }
> > 
> > ```
> > 
> > }'
> > 
> > Any idea why is such a behaviour is observed. I know \_boost should have  
> > different parameter that's why using a different parameter. As you told  
> > earlier if I want to use my "po" field in custom score query, I'll have to  
> > remove that \_boost segment. But I need \_boost so that I can add document  
> > boost to my docs. That's why checking with a small use case.
> > 
> > Please help !!!
> > 
> > Thanks
> > 
> > On Sat, Feb 1, 2014 at 2:09 AM, Mukul Gupta [mukulnitkkr@gmail.com](mailto:mukulnitkkr@gmail.com)wrote:
> > 
> > > Binh,
> > > 
> > > how can I add explain:true in that one ?
> > > 
> > > On Sat, Feb 1, 2014 at 1:47 AM, Binh Ly [binh@hibalo.com](mailto:binh@hibalo.com) wrote:
> > > 
> > > > Should be roughly like this:
> > > > 
> > > > {  
> > > > "query": {  
> > > > "custom\_score": {  
> > > > "query": {  
> > > > "query\_string": {  
> > > > "query": "blah blah",  
> > > > "fields": [  
> > > > "text^30",  
> > > > "ad",  
> > > > "st",  
> > > > "cn",  
> > > > "co"  
> > > > ],  
> > > > "default\_operator": "AND"  
> > > > }  
> > > > },  
> > > > "script": "\_score \* (doc['po'].empty ? 1 : doc['po'].value == 0.0  
> > > > ? 1 : doc['po'].value)"  
> > > > }  
> > > > }  
> > > > }
> > > > 
> > > > --  
> > > > 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+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
> > > > To view this discussion on the web visit  
> > > > [https://groups.google.com/d/msgid/elasticsearch/07ae02b5-39d9-410d-892e-8ff366de515c%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/07ae02b5-39d9-410d-892e-8ff366de515c%40googlegroups.com)  
> > > > .
> > > > 
> > > > For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).
> > 
> > --  
> > 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+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
> > To view this discussion on the web visit  
> > [https://groups.google.com/d/msgid/elasticsearch/CAAVTvp6anHtDAnj2AkkbADUEqDt7J7\_5XWQPJp6xP9t9G1F0ng%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CAAVTvp6anHtDAnj2AkkbADUEqDt7J7_5XWQPJp6xP9t9G1F0ng%40mail.gmail.com)  
> > .
> > 
> > For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).
> 
> --  
> 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+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
> To view this discussion on the web visit  
> [https://groups.google.com/d/msgid/elasticsearch/CALY%3DcQA6swutEJJFZbUTHkmyYTiaR\_szL%3DLFEDXakstf%3DtCeWg%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CALY%3DcQA6swutEJJFZbUTHkmyYTiaR_szL%3DLFEDXakstf%3DtCeWg%40mail.gmail.com)  
> .
> 
> For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

--  
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+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/CAAVTvp4KR2hsOx\_zN2q1erW9HO%3Do1AdpS%2BPuCTzpmGCWG3rFAw%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CAAVTvp4KR2hsOx_zN2q1erW9HO%3Do1AdpS%2BPuCTzpmGCWG3rFAw%40mail.gmail.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![Binh\_Ly](https://avatars.discourse-cdn.com/v4/letter/b/ce7236/32.png) [@Binh\_Ly](https://discuss.elastic.co/u/Binh_Ly)\
**Post date:** [January 31, 2014, 9:25pm UTC](https://discuss.elastic.co/t/what-will-be-the-equivalent-query-of-the-following-java-api/15536/10 "2014-01-31T21:25:01Z")

</div>

Just add explain: true at the top level 🙂

{  
"explain": true,  
"query": { blah blah }  
}

On Friday, January 31, 2014 3:39:19 PM UTC-5, coder wrote:

> Binh,
> 
> how can I add explain:true in that one ?

--  
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+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/ff6a4a6c-90fe-48a4-b7a3-230cbbc27528%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/ff6a4a6c-90fe-48a4-b7a3-230cbbc27528%40googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![seallison](https://avatars.discourse-cdn.com/v4/letter/s/4af34b/32.png) [@seallison](https://discuss.elastic.co/u/seallison)\
**Post date:** [January 31, 2014, 10:05pm UTC](https://discuss.elastic.co/t/what-will-be-the-equivalent-query-of-the-following-java-api/15536/11 "2014-01-31T22:05:07Z")

</div>

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+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/1a8462a6-59cc-4ae3-97e7-e51ef8ec719d%40googlegroups.com](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](https://groups.google.com/groups/opt_out).

---

<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:** [July 6, 2017, 1:53am UTC](https://discuss.elastic.co/t/what-will-be-the-equivalent-query-of-the-following-java-api/15536/12 "2017-07-06T01:53:31Z")

</div>


