Is it possible to use filtered query with custom filters score?

I need to search documents that are matching some filters. But i want
to sort them by custom score script.
FI:
filter by gender = 1

and calculate score:
if ( age > 10 )
_score = age * 2
else
_score = age * 1

Thats just an example do not try to understand the score function :smiley:

Is it possible?

Thanx

Yes, its possible. The query you specify within a custom_score query can be
any query you want to use.

On Thu, Sep 29, 2011 at 5:41 PM, BlueZero bluezero@bluezero.sk wrote:

I need to search documents that are matching some filters. But i want
to sort them by custom score script.
FI:
filter by gender = 1

and calculate score:
if ( age > 10 )
_score = age * 2
else
_score = age * 1

Thats just an example do not try to understand the score function :smiley:

Is it possible?

Thanx

Hm, ok, this is my request:

{
"from":0,
"size":"20",
"fields":
[
"idUser",
"online",
"idChat",
"lastUpdate"
],
"custom_filters_score":
{
"query":
{
"filtered":
{
"query":
{
"match_all":{}
},
"filter":
{
"and":
[
{
"term":
{
"userType":"0"
}
},
{
"term":
{
"NeDajVek":"0"
}
},
{
"numeric_range":
{
"Vek":
{
"from":14,
"to":50
}
}
},
{
"term":
{
"Pohlavie":"2"
}
},
{
"term":
{
"idKraj":"1"
}
},
{
"term":
{
"Fotka":"1"
}
},
{
"numeric_range":
{
"Level":
{
"from":1,
"to":10
}
}
}
],
"not":
}
},
"filters":
[
{
"filter":
{
"term":
{
"Vek":25
}
},
"boost":3
},
{
"filter":
{
"term":
{
"Vek":22
}
},
"boost":1
}
]
}
}
}

and i am getting this parse error:
[No parser for element [custom_filters_score]]

On Oct 2, 10:30 am, Shay Banon kim...@gmail.com wrote:

Yes, its possible. The query you specify within a custom_score query can be
any query you want to use.

On Thu, Sep 29, 2011 at 5:41 PM, BlueZero bluez...@bluezero.sk wrote:

I need to search documents that are matching some filters. But i want
to sort them by custom score script.
FI:
filter by gender = 1

and calculate score:
if ( age > 10 )
_score = age * 2
else
_score = age * 1

Thats just an example do not try to understand the score function :smiley:

Is it possible?

Thanx

You need to put the "custom_filters_score" element in a "query" element that
represents the "query" part of the search request (otherwise, the search
request can't tell where the query part is).

On Mon, Oct 3, 2011 at 10:20 AM, BlueZero bluezero@bluezero.sk wrote:

Hm, ok, this is my request:

{
"from":0,
"size":"20",
"fields":
[
"idUser",
"online",
"idChat",
"lastUpdate"
],
"custom_filters_score":
{
"query":
{
"filtered":
{
"query":
{
"match_all":{}
},
"filter":
{
"and":
[
{
"term":
{

"userType":"0"
}
},
{
"term":
{

"NeDajVek":"0"
}
},
{
"numeric_range":
{
"Vek":
{

"from":14,

"to":50
}
}
},
{
"term":
{

"Pohlavie":"2"
}
},
{
"term":
{
"idKraj":"1"
}
},
{
"term":
{
"Fotka":"1"
}
},
{
"numeric_range":
{
"Level":
{

"from":1,

"to":10
}
}
}
],
"not":
}
},
"filters":
[
{
"filter":
{
"term":
{
"Vek":25
}
},
"boost":3
},
{
"filter":
{
"term":
{
"Vek":22
}
},
"boost":1
}
]
}
}
}

and i am getting this parse error:
[No parser for element [custom_filters_score]]

On Oct 2, 10:30 am, Shay Banon kim...@gmail.com wrote:

Yes, its possible. The query you specify within a custom_score query can
be
any query you want to use.

On Thu, Sep 29, 2011 at 5:41 PM, BlueZero bluez...@bluezero.sk wrote:

I need to search documents that are matching some filters. But i want
to sort them by custom score script.
FI:
filter by gender = 1

and calculate score:
if ( age > 10 )
_score = age * 2
else
_score = age * 1

Thats just an example do not try to understand the score function :smiley:

Is it possible?

Thanx

I've tried to put it almost everywhere.
Shay, can i politely ask you to alter my request to correct order?
Thank you very much.

On Oct 3, 11:36 am, Shay Banon kim...@gmail.com wrote:

You need to put the "custom_filters_score" element in a "query" element that
represents the "query" part of the search request (otherwise, the search
request can't tell where the query part is).

On Mon, Oct 3, 2011 at 10:20 AM, BlueZero bluez...@bluezero.sk wrote:

Hm, ok, this is my request:

{
"from":0,
"size":"20",
"fields":
[
"idUser",
"online",
"idChat",
"lastUpdate"
],
"custom_filters_score":
{
"query":
{
"filtered":
{
"query":
{
"match_all":{}
},
"filter":
{
"and":
[
{
"term":
{

"userType":"0"
}
},
{
"term":
{

"NeDajVek":"0"
}
},
{
"numeric_range":
{
"Vek":
{

"from":14,

"to":50
}
}
},
{
"term":
{

"Pohlavie":"2"
}
},
{
"term":
{
"idKraj":"1"
}
},
{
"term":
{
"Fotka":"1"
}
},
{
"numeric_range":
{
"Level":
{

"from":1,

"to":10
}
}
}
],
"not":
}
},
"filters":
[
{
"filter":
{
"term":
{
"Vek":25
}
},
"boost":3
},
{
"filter":
{
"term":
{
"Vek":22
}
},
"boost":1
}
]
}
}
}

and i am getting this parse error:
[No parser for element [custom_filters_score]]

On Oct 2, 10:30 am, Shay Banon kim...@gmail.com wrote:

Yes, its possible. The query you specify within a custom_score query can
be
any query you want to use.

On Thu, Sep 29, 2011 at 5:41 PM, BlueZero bluez...@bluezero.sk wrote:

I need to search documents that are matching some filters. But i want
to sort them by custom score script.
FI:
filter by gender = 1

and calculate score:
if ( age > 10 )
_score = age * 2
else
_score = age * 1

Thats just an example do not try to understand the score function :smiley:

Is it possible?

Thanx

On Mon, 2011-10-03 at 04:19 -0700, BlueZero wrote:

I've tried to put it almost everywhere.
Shay, can i politely ask you to alter my request to correct order?

just change:

"custom_filters_score": {.... }

to:
"query": {
"custom_filters_score": {.... }
}

clint

Thank you, works

On Oct 3, 1:29 pm, Clinton Gormley cl...@traveljury.com wrote:

On Mon, 2011-10-03 at 04:19 -0700, BlueZero wrote:

I've tried to put it almost everywhere.
Shay, can i politely ask you to alter my request to correct order?

just change:

"custom_filters_score": {.... }

to:
"query": {
"custom_filters_score": {.... }
}

clint

Can you please show me the final query that works? I am trying to do
something similar using a filtered query and then applying custom filter
score to the filtered query.

Thanks!

On Thursday, September 29, 2011 10:41:29 AM UTC-4, BlueZero wrote:

I need to search documents that are matching some filters. But i want
to sort them by custom score script.
FI:
filter by gender = 1

and calculate score:
if ( age > 10 )
_score = age * 2
else
_score = age * 1

Thats just an example do not try to understand the score function :smiley:

Is it possible?

Thanx

--
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/33ad8ad4-b5f2-4a3a-8949-ae68198dd5cd%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.