Ordering Search Result Based On User Context


(krisread) #1

Hi,

I'm new to ES. We want to search a collection of documents, but then
order and filter the result-set based on user-context data from
outside the actual documents themselves.

For example, we want to search for "Rabbit" among all "Animal"
documents. However, we want to order the results based not just on
document relevancy to the search term "Rabbit" but also on other
factors not even contained int he "Animal" documents, such as where
the searcher is located, what the most popular searched-for Animals
were that day, what browser the search user is using on the website,
or what species of Animals that this user has searched for in the
past.

We don't want to post-process the search results... can we handle all
of this within ES? Can we have multiple indexes and/or multiple
types, each of which collects different types of data (one index on
Animals, another on User Locations, another on User Browsers, etc),
and then query based on something like a join or intersection?

I realize some things could be passed in with the query as additional
query parameters... but this doesn't cover when we need to compute
weights based on complex combinations of aggregate data points.

Suggestions?


(ppearcy) #2

Hey,
Check out script based sorting:
http://www.elasticsearch.org/guide/reference/api/search/script-fields.html

You can do a lot of cool stuff with this. It allows you to sort on the
data contained in the document, as well as, inputs that are passed
into the sort function.

I think this will meet your needs.

Best Regards,
Paul

On Jul 12, 2:38 pm, krisread kris.r...@gmail.com wrote:

Hi,

I'm new to ES. We want to search a collection of documents, but then
order and filter the result-set based on user-context data from
outside the actual documents themselves.

For example, we want to search for "Rabbit" among all "Animal"
documents. However, we want to order the results based not just on
document relevancy to the search term "Rabbit" but also on other
factors not even contained int he "Animal" documents, such as where
the searcher is located, what the most popular searched-for Animals
were that day, what browser the search user is using on the website,
or what species of Animals that this user has searched for in the
past.

We don't want to post-process the search results... can we handle all
of this within ES? Can we have multiple indexes and/or multiple
types, each of which collects different types of data (one index on
Animals, another on User Locations, another on User Browsers, etc),
and then query based on something like a join or intersection?

I realize some things could be passed in with the query as additional
query parameters... but this doesn't cover when we need to compute
weights based on complex combinations of aggregate data points.

Suggestions?


(Karussell) #3

you can also use boosts queries:

http://www.elasticsearch.org/guide/reference/query-dsl/boosting-query.html

http://www.elasticsearch.org/guide/reference/query-dsl/bool-query.html

E.g. for jetsli.de I'm boosting documents which are in the language of
the users' browser language:

BoolQueryBuilder bqb = QueryBuilders.boolQuery();
// here your normal query
bqb.must(qb);
// if you omit the following, other languages will be completely
excluded
bqb.should(QueryBuilders.matchAllQuery());
// now the boost
bqb.should(QueryBuilders.termQuery("lang", userLanguage).boost(1.2f));

But keep in mind this will be slower then the pure "qb" query ...

when using scripting the fastest solution is when you use native
scripts

Regards,
Peter.


(system) #4