I have a search with a field sort (using Java API) that throws an exception
if the index is empty.
I believe this is because my empty index has no mappings defined, and the
sort cannot figure out the data type of the field in question (even though
there are no results to sort). What is the best way to deal with this case?
I can think of a couple of ways:
Insert a dummy record so ES can determine the mappings (kind of hacky)
Define explicit mappings when I create the index (a little annoying,
since I find the default mappings useful and would prefer to use them)
Do an additional index status request first to see if the document count
is zero (has to be done on every request)
Catch the exception (seems dangerous because I don't think I get the
real cause (missing mapping) except as part of the message text)
The best way is to define the mapping just for the relevant field you plan to sort on. There is different support for sorting based on the field type derived/defined, thats why its required.
On Saturday, March 26, 2011 at 12:22 AM, Curtis Caravone wrote:
I know this is an edge case, but...
I have a search with a field sort (using Java API) that throws an exception if the index is empty.
I believe this is because my empty index has no mappings defined, and the sort cannot figure out the data type of the field in question (even though there are no results to sort). What is the best way to deal with this case? I can think of a couple of ways:
Insert a dummy record so ES can determine the mappings (kind of hacky)
Define explicit mappings when I create the index (a little annoying, since I find the default mappings useful and would prefer to use them)
Do an additional index status request first to see if the document count is zero (has to be done on every request)
Catch the exception (seems dangerous because I don't think I get the real cause (missing mapping) except as part of the message text)
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.