Using term queries with two different script based custom filter

Hi,

I need to to club a set of term queries with two different script based
custom filter score query.
I have done this clubbing of queries and filters by using the bool filter
but when i run this, i get results with score =1.

I am not sure whether this approach is correct or not.
Also i am not able to get why the score is 1 even after the use of script.

Please help.

Thanks in advance.

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

Can you please post the query you are executing and elaborate a bit more on
what you want to achieve with it?

On Monday, September 9, 2013 5:06:40 PM UTC+2, Harshit Mathur wrote:

Hi,

I need to to club a set of term queries with two different script based
custom filter score query.
I have done this clubbing of queries and filters by using the bool filter
but when i run this, i get results with score =1.

I am not sure whether this approach is correct or not.
Also i am not able to get why the score is 1 even after the use of script.

Please help.

Thanks in advance.

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

hi

Thanks for answering,

Actually, I want to run a combine query where first i will be selecting
docs based on FACTOR field (using bool query), then apply custom score
filter query based on the two scripts.
Below is the query,

{
"filtered" : {
"query" : {
"match_all" : { }
},
"filter" : {
"bool" : {
"must" : [ {
"query" : {
"custom_score" : {
"query" : {
"match_all" : { }
},
"script" : "(doc['SPIRIT'].value / 10)"
}
}
}, {
"query" : {
"custom_score" : {
"query" : {
"match_all" : { }
},
"script" : "max (((2013 - doc['YEAR'].value) / 20), 0)"
}
}
} ],
"should" : {
"query" : {
"bool" : {
"should" : [ {
"term" : {
"FACTOR" : {
"value" : "31",
"boost" : 2.0
}
}
}, {
"term" : {
"FACTOR" : {
"value" : "252",
"boost" : 1.0
}
}
}, {
"term" : {
"FACTOR" : {
"value" : "276",
"boost" : 2.0
}
}
}, {
"term" : {
"FACTOR" : {
"value" : "23",
"boost" : 1.0
}
}
}, {
"term" : {
"FACTOR" : {
"value" : "9",
"boost" : 2.0
}
}
} ]
}
}
}
}
}
}
}

On Monday, September 9, 2013 10:03:55 PM UTC+5:30, Luca Cavanna wrote:

Can you please post the query you are executing and elaborate a bit more
on what you want to achieve with it?

On Monday, September 9, 2013 5:06:40 PM UTC+2, Harshit Mathur wrote:

Hi,

I need to to club a set of term queries with two different script based
custom filter score query.
I have done this clubbing of queries and filters by using the bool filter
but when i run this, i get results with score =1.

I am not sure whether this approach is correct or not.
Also i am not able to get why the score is 1 even after the use of script.

Please help.

Thanks in advance.

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

Hi,
thanks for posting the query.

The problem is that you put the scoring logic in the filter block, which is
wrapped into a ConstantScoreQuery that always returns 1. In fact filters
are not scored, but meant to be used to exclude documents the query need to
be executed on. I would just move the whole scoring block to the query part
of the json object. You don't seem to have any filter in your query, thus I
don't think you need the filtered query either.

Cheers
Luca

On Tuesday, September 10, 2013 7:01:34 AM UTC+2, Harshit Mathur wrote:

hi

Thanks for answering,

Actually, I want to run a combine query where first i will be selecting
docs based on FACTOR field (using bool query), then apply custom score
filter query based on the two scripts.
Below is the query,

{
"filtered" : {
"query" : {
"match_all" : { }
},
"filter" : {
"bool" : {
"must" : [ {
"query" : {
"custom_score" : {
"query" : {
"match_all" : { }
},
"script" : "(doc['SPIRIT'].value / 10)"
}
}
}, {
"query" : {
"custom_score" : {
"query" : {
"match_all" : { }
},
"script" : "max (((2013 - doc['YEAR'].value) / 20), 0)"
}
}
} ],
"should" : {
"query" : {
"bool" : {
"should" : [ {
"term" : {
"FACTOR" : {
"value" : "31",
"boost" : 2.0
}
}
}, {
"term" : {
"FACTOR" : {
"value" : "252",
"boost" : 1.0
}
}
}, {
"term" : {
"FACTOR" : {
"value" : "276",
"boost" : 2.0
}
}
}, {
"term" : {
"FACTOR" : {
"value" : "23",
"boost" : 1.0
}
}
}, {
"term" : {
"FACTOR" : {
"value" : "9",
"boost" : 2.0
}
}
} ]
}
}
}
}
}
}
}

On Monday, September 9, 2013 10:03:55 PM UTC+5:30, Luca Cavanna wrote:

Can you please post the query you are executing and elaborate a bit more
on what you want to achieve with it?

On Monday, September 9, 2013 5:06:40 PM UTC+2, Harshit Mathur wrote:

Hi,

I need to to club a set of term queries with two different script based
custom filter score query.
I have done this clubbing of queries and filters by using the bool filter
but when i run this, i get results with score =1.

I am not sure whether this approach is correct or not.
Also i am not able to get why the score is 1 even after the use of
script.

Please help.

Thanks in advance.

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

Hi,

Thanks for the reply.
I got a bit confused, can you please correct the query for me.
You said about constant score query, but i have used custom score query.

Please help.

Thanks,

Harshit
On 12 Sep 2013 17:16, "Luca Cavanna" cavannaluca@gmail.com wrote:

Hi,
thanks for posting the query.

The problem is that you put the scoring logic in the filter block, which
is wrapped into a ConstantScoreQuery that always returns 1. In fact filters
are not scored, but meant to be used to exclude documents the query need to
be executed on. I would just move the whole scoring block to the query part
of the json object. You don't seem to have any filter in your query, thus I
don't think you need the filtered query either.

Cheers
Luca

On Tuesday, September 10, 2013 7:01:34 AM UTC+2, Harshit Mathur wrote:

hi

Thanks for answering,

Actually, I want to run a combine query where first i will be selecting
docs based on FACTOR field (using bool query), then apply custom score
filter query based on the two scripts.
Below is the query,

{
"filtered" : {
"query" : {
"match_all" : { }
},
"filter" : {
"bool" : {
"must" : [ {
"query" : {
"custom_score" : {
"query" : {
"match_all" : { }
},
"script" : "(doc['SPIRIT'].value / 10)"
}
}
}, {
"query" : {
"custom_score" : {
"query" : {
"match_all" : { }
},
"script" : "max (((2013 - doc['YEAR'].value) / 20), 0)"
}
}
} ],
"should" : {
"query" : {
"bool" : {
"should" : [ {
"term" : {
"FACTOR" : {
"value" : "31",
"boost" : 2.0
}
}
}, {
"term" : {
"FACTOR" : {
"value" : "252",
"boost" : 1.0
}
}
}, {
"term" : {
"FACTOR" : {
"value" : "276",
"boost" : 2.0
}
}
}, {
"term" : {
"FACTOR" : {
"value" : "23",
"boost" : 1.0
}
}
}, {
"term" : {
"FACTOR" : {
"value" : "9",
"boost" : 2.0
}
}
} ]
}
}
}
}
}
}
}

On Monday, September 9, 2013 10:03:55 PM UTC+5:30, Luca Cavanna wrote:

Can you please post the query you are executing and elaborate a bit more
on what you want to achieve with it?

On Monday, September 9, 2013 5:06:40 PM UTC+2, Harshit Mathur wrote:

Hi,

I need to to club a set of term queries with two different script based
custom filter score query.
I have done this clubbing of queries and filters by using the bool
filter
but when i run this, i get results with score =1.

I am not sure whether this approach is correct or not.
Also i am not able to get why the score is 1 even after the use of
script.

Please help.

Thanks in advance.

--
You received this message because you are subscribed to a topic in the
Google Groups "elasticsearch" group.
To unsubscribe from this topic, visit
https://groups.google.com/d/topic/elasticsearch/CptEL1NlyfA/unsubscribe.
To unsubscribe from this group and all its topics, send an email to
elasticsearch+unsubscribe@googlegroups.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.
For more options, visit https://groups.google.com/groups/opt_out.

No worries, the important bit is that filters don't have any score, but are
meant to be used to excude results from the resultset. The part of your
query that needs to influence the score needs to be submitted as a query,
and as far as I can see you don't have any filter in your query. Therefore
you can remove the filtered query and move two levels up your bool query,
like this:

{
"bool" : {
"must" : [
here go your must clauses
],
"should" :[
here go your should clauses
]
}
}

On Fri, Sep 13, 2013 at 6:34 AM, Harshit Mathur mathursharp@gmail.comwrote:

Hi,

Thanks for the reply.
I got a bit confused, can you please correct the query for me.
You said about constant score query, but i have used custom score query.

Please help.

Thanks,

Harshit
On 12 Sep 2013 17:16, "Luca Cavanna" cavannaluca@gmail.com wrote:

Hi,
thanks for posting the query.

The problem is that you put the scoring logic in the filter block, which
is wrapped into a ConstantScoreQuery that always returns 1. In fact filters
are not scored, but meant to be used to exclude documents the query need to
be executed on. I would just move the whole scoring block to the query part
of the json object. You don't seem to have any filter in your query, thus I
don't think you need the filtered query either.

Cheers
Luca

On Tuesday, September 10, 2013 7:01:34 AM UTC+2, Harshit Mathur wrote:

hi

Thanks for answering,

Actually, I want to run a combine query where first i will be selecting
docs based on FACTOR field (using bool query), then apply custom score
filter query based on the two scripts.
Below is the query,

{
"filtered" : {
"query" : {
"match_all" : { }
},
"filter" : {
"bool" : {
"must" : [ {
"query" : {
"custom_score" : {
"query" : {
"match_all" : { }
},
"script" : "(doc['SPIRIT'].value / 10)"
}
}
}, {
"query" : {
"custom_score" : {
"query" : {
"match_all" : { }
},
"script" : "max (((2013 - doc['YEAR'].value) / 20), 0)"
}
}
} ],
"should" : {
"query" : {
"bool" : {
"should" : [ {
"term" : {
"FACTOR" : {
"value" : "31",
"boost" : 2.0
}
}
}, {
"term" : {
"FACTOR" : {
"value" : "252",
"boost" : 1.0
}
}
}, {
"term" : {
"FACTOR" : {
"value" : "276",
"boost" : 2.0
}
}
}, {
"term" : {
"FACTOR" : {
"value" : "23",
"boost" : 1.0
}
}
}, {
"term" : {
"FACTOR" : {
"value" : "9",
"boost" : 2.0
}
}
} ]
}
}
}
}
}
}
}

On Monday, September 9, 2013 10:03:55 PM UTC+5:30, Luca Cavanna wrote:

Can you please post the query you are executing and elaborate a bit
more on what you want to achieve with it?

On Monday, September 9, 2013 5:06:40 PM UTC+2, Harshit Mathur wrote:

Hi,

I need to to club a set of term queries with two different script based
custom filter score query.
I have done this clubbing of queries and filters by using the bool
filter
but when i run this, i get results with score =1.

I am not sure whether this approach is correct or not.
Also i am not able to get why the score is 1 even after the use of
script.

Please help.

Thanks in advance.

--
You received this message because you are subscribed to a topic in the
Google Groups "elasticsearch" group.
To unsubscribe from this topic, visit
https://groups.google.com/d/topic/elasticsearch/CptEL1NlyfA/unsubscribe.
To unsubscribe from this group and all its topics, send an email to
elasticsearch+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

--
You received this message because you are subscribed to a topic in the
Google Groups "elasticsearch" group.
To unsubscribe from this topic, visit
https://groups.google.com/d/topic/elasticsearch/CptEL1NlyfA/unsubscribe.
To unsubscribe from this group and all its topics, send an email to
elasticsearch+unsubscribe@googlegroups.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.
For more options, visit https://groups.google.com/groups/opt_out.