Random sorting

Hello!

Is it possible to set up sorting to return items at random based on one of
the field?

Something like :

{
"sort" : {
{ "post_date" : {"order" : "RANDOM"} },
"user" : { },
"_score" : { }
},
"query" : {
"term" : { "user" : "kimchy" }
}
}

Or any other possibilities to get a random responce.

Thanks,
Andrey.

Try a custom score function with a random seed returned

Peter.

On Nov 7, 2:12 pm, Андрей Смолев andrey.smo...@gmail.com wrote:

Hello!

Is it possible to set up sorting to return items at random based on one of
the field?

Something like :

{
"sort" : {
{ "post_date" : {"order" : "RANDOM"} },
"user" : { },
"_score" : { }
},
"query" : {
"term" : { "user" : "kimchy" }
}

}

Or any other possibilities to get a random responce.

Thanks,
Andrey.

Thank you! Looks like an answer!
On Nov 7, 2011 6:44 PM, "Karussell" tableyourtime@googlemail.com wrote:

Try a custom score function with a random seed returned

Peter.

On Nov 7, 2:12 pm, Андрей Смолев andrey.smo...@gmail.com wrote:

Hello!

Is it possible to set up sorting to return items at random based on one
of
the field?

Something like :

{
"sort" : {
{ "post_date" : {"order" : "RANDOM"} },
"user" : { },
"_score" : { }
},
"query" : {
"term" : { "user" : "kimchy" }
}

}

Or any other possibilities to get a random responce.

Thanks,
Andrey.

Hi Andre,

Do you have a code example for this solution? Trying to do the same
thing, but not entirely sure what it actually looks like...

Thanks!
-Kunal

On Nov 7, 12:05 pm, Андрей Смолев andrey.smo...@gmail.com wrote:

Thank you! Looks like an answer!
On Nov 7, 2011 6:44 PM, "Karussell" tableyourt...@googlemail.com wrote:

Try a custom score function with a random seed returned

Peter.

On Nov 7, 2:12 pm, Андрей Смолев andrey.smo...@gmail.com wrote:

Hello!

Is it possible to set up sorting to return items at random based on one
of
the field?

Something like :

{
"sort" : {
{ "post_date" : {"order" : "RANDOM"} },
"user" : { },
"_score" : { }
},
"query" : {
"term" : { "user" : "kimchy" }
}

}

Or any other possibilities to get a random responce.

Thanks,
Andrey.

I tried to use custom_score but i had an syntax error. What do i do wrong?

_search?source={"custom_score":{{"query":{"query_string":{"default_field":"_all",
"default_operator":"AND","query":"майка~0.7"}},"size":10},"script":"_score"
}}

{
"error": "SearchPhaseExecutionException[Failed to execute phase [query],
total failure; shardFailures {[LS6ki3GCS_yyziipuYI9Og][vitrina][3]:
RemoteTransportException[[Arlok][inet[/10.10.205.24:9300]][search/phase/query]];
nested: SearchParseException[[vitrina][3]: from[-1],size[-1]: Parse Failure
[Failed to parse source
[{"custom_score":{{"query":{"query_string":{"default_field":"_all",
"default_operator":"AND","query":"майка~0.7"}},"size":10},"script":"_score"
}}]]]; nested: SearchParseException[[vitrina][3]: from[-1],size[-1]: Parse
Failure [No parser for element [custom_score]]];
}{[Cq6VIo58SQCCjpMay6KrhQ][vitrina][0]: SearchParseException[[vitrina][0]:
from[-1],size[-1]: Parse Failure [Failed to parse source
[{"custom_score":{{"query":{"query_string":{"default_field":"_all",
"default_operator":"AND","query":"майка~0.7"}},"size":10},"script":"_score"
}}]]]; nested: SearchParseException[[vitrina][0]: from[-1],size[-1]: Parse
Failure [No parser for element [custom_score]]];
}{[Cq6VIo58SQCCjpMay6KrhQ][vitrina][1]: SearchParseException[[vitrina][1]:
from[-1],size[-1]: Parse Failure [Failed to parse source
[{"custom_score":{{"query":{"query_string":{"default_field":"_all",
"default_operator":"AND","query":"майка~0.7"}},"size":10},"script":"_score"
}}]]]; nested: SearchParseException[[vitrina][1]: from[-1],size[-1]: Parse
Failure [No parser for element [custom_score]]];
}{[qqcovTfeRg2mk72Yjf0OIA][vitrina][2]: RemoteTransportException[[Devil
Dinosaur][inet[/10.10.205.25:9300]][search/phase/query]]; nested:
SearchParseException[[vitrina][2]: from[-1],size[-1]: Parse Failure [Failed
to parse source
[{"custom_score":{{"query":{"query_string":{"default_field":"_all",
"default_operator":"AND","query":"майка~0.7"}},"size":10},"script":"_score"
}}]]]; nested: SearchParseException[[vitrina][2]: from[-1],size[-1]: Parse
Failure [No parser for element [custom_score]]];
}{[LS6ki3GCS_yyziipuYI9Og][vitrina][4]:
RemoteTransportException[[Arlok][inet[/10.10.205.24:9300]][search/phase/query]];
nested: SearchParseException[[vitrina][4]: from[-1],size[-1]: Parse Failure
[Failed to parse source
[{"custom_score":{{"query":{"query_string":{"default_field":"_all",
"default_operator":"AND","query":"майка~0.7"}},"size":10},"script":"_score"
}}]]]; nested: SearchParseException[[vitrina][4]: from[-1],size[-1]: Parse
Failure [No parser for element [custom_score]]]; }]",
"status": 500
}

On Mon, Nov 7, 2011 at 7:44 PM, Karussell tableyourtime@googlemail.comwrote:

Try a custom score function with a random seed returned

Peter.

On Nov 7, 2:12 pm, Андрей Смолев andrey.smo...@gmail.com wrote:

Hello!

Is it possible to set up sorting to return items at random based on one
of
the field?

Something like :

{
"sort" : {
{ "post_date" : {"order" : "RANDOM"} },
"user" : { },
"_score" : { }
},
"query" : {
"term" : { "user" : "kimchy" }
}

}

Or any other possibilities to get a random responce.

Thanks,
Andrey.

On Wed, 2011-11-09 at 14:56 +0400, Андрей Смолев wrote:

I tried to use custom_score but i had an syntax error. What do i do
wrong?

_search?source={"custom_score":{{"query":{"query_string":{"default_field":"_all", "default_operator":"AND","query":"майка~0.7"}},"size":10},"script":"_score" }}

the 'custom_score' should be wrapped by an outer {query: {...}}

clint

Ohh, i see!

Here is a working example if anyone is interested:

source={"query":{"custom_score":{"script":"random()*20","query":{"query_string":{"default_field":"_all",
"default_operator":"AND","query":"майка~0.7"}},"size":10}},"sort":{"_score":{"order":"desc"}}}

On Wed, Nov 9, 2011 at 3:01 PM, Clinton Gormley clint@traveljury.comwrote:

On Wed, 2011-11-09 at 14:56 +0400, Андрей Смолев wrote:

I tried to use custom_score but i had an syntax error. What do i do
wrong?

_search?source={"custom_score":{{"query":{"query_string":{"default_field":"_all",
"default_operator":"AND","query":"майка~0.7"}},"size":10},"script":"_score"
}}

the 'custom_score' should be wrapped by an outer {query: {...}}

clint

I'm trying to do something like this with a match all query...I want a
random sampling of my entire record set. Using this custom score
script approach to return a subset of 100,000 random records yields a
very slow query (minutes) against the data set (~100 million records
total). So it must be scanning through all the records before
returning the random results... Does anyone know a more efficient way
to accomplish this? Thanks.

On Nov 9, 6:17 am, Андрей Смолев andrey.smo...@gmail.com wrote:

Ohh, i see!

Here is a working example if anyone is interested:

source={"query":{"custom_score":{"script":"random()*20","query":{"query_string":{"default_field":"_all",
"default_operator":"AND","query":"майка~0.7"}},"size":10}},"sort":{"_score":{"order":"desc"}}}

On Wed, Nov 9, 2011 at 3:01 PM, Clinton Gormley cl...@traveljury.comwrote:

On Wed, 2011-11-09 at 14:56 +0400, Андрей Смолев wrote:

I tried to use custom_score but i had an syntax error. What do i do
wrong?

_search?source={"custom_score":{{"query":{"query_string":{"default_field":"_all",
"default_operator":"AND","query":"майка~0.7"}},"size":10},"script":"_score"
}}

the 'custom_score' should be wrapped by an outer {query: {...}}

clint