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


(dark_shadow) #1

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.
To view this discussion on the web visit 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.


(seallison) #2

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.
To view this discussion on the web visit 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.


(dark_shadow) #3

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

On Sat, Feb 1, 2014 at 1:15 AM, seallison 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.
To view this discussion on the web visit
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.

--
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.
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.
For more options, visit https://groups.google.com/groups/opt_out.


(Binh Ly) #4

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.
To view this discussion on the web visit 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.


(dark_shadow) #5

Binh,

how can I add explain:true in that one ?

On Sat, Feb 1, 2014 at 1:47 AM, Binh Ly 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.
To view this discussion on the web visit
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.

--
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.
To view this discussion on the web visit https://groups.google.com/d/msgid/elasticsearch/CAAVTvp4tYv6S2otq3iGX6ssRg4p3QZPRUePJhZjLEyvQ84%3DMAg%40mail.gmail.com.
For more options, visit https://groups.google.com/groups/opt_out.


(dark_shadow) #6

Binh,

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

curl -XPUT '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 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 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.
To view this discussion on the web visit
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.

--
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.
To view this discussion on the web visit https://groups.google.com/d/msgid/elasticsearch/CAAVTvp6anHtDAnj2AkkbADUEqDt7J7_5XWQPJp6xP9t9G1F0ng%40mail.gmail.com.
For more options, visit https://groups.google.com/groups/opt_out.


(Ivan Brusic) #7

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 wrote:

Binh,

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

curl -XPUT '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 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 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.
To view this discussion on the web visit
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.

--
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.
To view this discussion on the web visit
https://groups.google.com/d/msgid/elasticsearch/CAAVTvp6anHtDAnj2AkkbADUEqDt7J7_5XWQPJp6xP9t9G1F0ng%40mail.gmail.com
.

For more options, visit 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.
To view this discussion on the web visit 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.


(dark_shadow) #8

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 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.comwrote:

Binh,

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

curl -XPUT '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.comwrote:

Binh,

how can I add explain:true in that one ?

On Sat, Feb 1, 2014 at 1:47 AM, Binh Ly 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.
To view this discussion on the web visit
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.

--
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.
To view this discussion on the web visit
https://groups.google.com/d/msgid/elasticsearch/CAAVTvp6anHtDAnj2AkkbADUEqDt7J7_5XWQPJp6xP9t9G1F0ng%40mail.gmail.com
.

For more options, visit 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.
To view this discussion on the web visit
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.

--
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.
To view this discussion on the web visit https://groups.google.com/d/msgid/elasticsearch/CAAVTvp4dGscR7eHGvaNvEu341OwVeXVpgc5R8%2BEbt%2BbEYnu3Ow%40mail.gmail.com.
For more options, visit https://groups.google.com/groups/opt_out.


(dark_shadow) #9

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 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.comwrote:

Binh,

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

curl -XPUT '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.comwrote:

Binh,

how can I add explain:true in that one ?

On Sat, Feb 1, 2014 at 1:47 AM, Binh Ly 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.
To view this discussion on the web visit
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.

--
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.
To view this discussion on the web visit
https://groups.google.com/d/msgid/elasticsearch/CAAVTvp6anHtDAnj2AkkbADUEqDt7J7_5XWQPJp6xP9t9G1F0ng%40mail.gmail.com
.

For more options, visit 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.
To view this discussion on the web visit
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.

--
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.
To view this discussion on the web visit 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.


(Binh Ly) #10

Just add explain: true at the top level :slight_smile:

{
"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.
To view this discussion on the web visit 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.


(seallison) #11

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.
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.


(system) #12