Lookup table for custom sorting


(Jack-2) #1

Hello,

I've searched the documentation and the internet, and I have some questions
about normalized data / sorting in ES.

Our application has some normalized data in Elasticsearch, i.e. documents
like

{ widgetNumber: 10, text: "Hello, World!" }
{ widgetNumber: 10, text: "Qwerty12345" }
{ widgetNumber: 99, text: "Blah." }

where widgetNumber: 10 corresponds to the string "foo" and widgetNumber:99
corresponds to the string "bar".

We never need to do text searches on widget, and widget's value may be
updated often, so we keep it normalized.

However, we do want to be able to sort results by widget's value. The
approach I'm trying is to make a lookup table for widget so that the custom
sort script would look like
"n = doc['widgetNumber'].value; return lookup[n];"
where "lookup" is a parameter to the script.

This works as expected, but it requires that you send the lookup table to
ES. Is there a mechanism to store this table in ES for use in the script?
Perhaps it is feasible with some small extensions/plugins?

Failing that, is there a different approach entirely that I should be using?

Many thanks,
Jack


(Shay Banon) #2

You can write a plugin that has a custom search script that does that. The
script, on the factory level, can go to the external data that has hte
mapping, and load it to memory, and then do the mapping, refreshing it now
and then. There was a thread on the mailing list that did it and gisted a
great sample for it, can't find it now...

On Thu, Apr 26, 2012 at 1:27 AM, Jack jbnine1@gmail.com wrote:

Hello,

I've searched the documentation and the internet, and I have some
questions about normalized data / sorting in ES.

Our application has some normalized data in Elasticsearch, i.e. documents
like

{ widgetNumber: 10, text: "Hello, World!" }
{ widgetNumber: 10, text: "Qwerty12345" }
{ widgetNumber: 99, text: "Blah." }

where widgetNumber: 10 corresponds to the string "foo" and widgetNumber:99
corresponds to the string "bar".

We never need to do text searches on widget, and widget's value may be
updated often, so we keep it normalized.

However, we do want to be able to sort results by widget's value. The
approach I'm trying is to make a lookup table for widget so that the custom
sort script would look like
"n = doc['widgetNumber'].value; return lookup[n];"
where "lookup" is a parameter to the script.

This works as expected, but it requires that you send the lookup table to
ES. Is there a mechanism to store this table in ES for use in the script?
Perhaps it is feasible with some small extensions/plugins?

Failing that, is there a different approach entirely that I should be
using?

Many thanks,
Jack


(system) #3