I'm curious how others here index fields with different units, e.g. 5
miles and 10 km, and support queries (and facets) that then use either
miles or km.
Given a document with a property like:
distance : {
value : 5,
unit : 'miles'
}
I want to index:
distance : 8046.72, // normalized to m
But I'd still like _source to contain the original value and unit, so
the original document can be returned.
One way to handle this right now is to index:
distance : { // don't index this
value : 5,
unit : 'miles'
},
_distance : 8046.72 // index this
...and rewrite queries to use _distance (after converting the values
in the query as required). For facets, value_script can be used.
But perhaps there is a better way (e.g. create a custom field type)?
You could use multi field type and use one of them for normalization (e.g.
to meter) or index both units: distance.km and distance.miles
Peter.
On Tuesday, March 6, 2012 8:31:42 AM UTC+1, Eric Jain wrote:
I'm curious how others here index fields with different units, e.g. 5
miles and 10 km, and support queries (and facets) that then use either
miles or km.
Given a document with a property like:
distance : {
value : 5,
unit : 'miles'
}
I want to index:
distance : 8046.72, // normalized to m
But I'd still like _source to contain the original value and unit, so
the original document can be returned.
One way to handle this right now is to index:
distance : { // don't index this
value : 5,
unit : 'miles'
},
_distance : 8046.72 // index this
...and rewrite queries to use _distance (after converting the values
in the query as required). For facets, value_script can be used.
But perhaps there is a better way (e.g. create a custom field type)?
Its better to create index a normalized value with the same unit across all docs. You can still index 5 and miles, but add another field that has a normalized value (for example, in miles), and use that when searching.
On Tuesday, March 6, 2012 at 11:13 AM, Eric Jain wrote:
On Tue, Mar 6, 2012 at 11:38, Shay Banon kimchy@gmail.com wrote:
Its better to create index a normalized value with the same unit across all
docs. You can still index 5 and miles, but add another field that has a
normalized value (for example, in miles), and use that when searching.
Creating separate, normalized fields is what I'm doing now. But I was
wondering how difficult it would be to create a custom "dimension"
type that normalizes units, so documents and queries don't need to be
pre/post processed explicitly?
You can create a customized type, which expects to accept a json object with the value and unit, and automatically index a normalized field. Hard to answer how difficult it is
On Tuesday, March 6, 2012 at 10:18 PM, Eric Jain wrote:
Its better to create index a normalized value with the same unit across all
docs. You can still index 5 and miles, but add another field that has a
normalized value (for example, in miles), and use that when searching.
Creating separate, normalized fields is what I'm doing now. But I was
wondering how difficult it would be to create a custom "dimension"
type that normalizes units, so documents and queries don't need to be
pre/post processed explicitly?
Apache, Apache Lucene, Apache Hadoop, Hadoop, HDFS and the yellow elephant
logo are trademarks of the
Apache Software Foundation
in the United States and/or other countries.