Searching an empty index

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:

  1. Insert a dummy record so ES can determine the mappings (kind of hacky)
  2. Define explicit mappings when I create the index (a little annoying,
    since I find the default mappings useful and would prefer to use them)
  3. Do an additional index status request first to see if the document count
    is zero (has to be done on every request)
  4. Catch the exception (seems dangerous because I don't think I get the
    real cause (missing mapping) except as part of the message text)
  5. other ideas?

thanks,

Curtis

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:

  1. Insert a dummy record so ES can determine the mappings (kind of hacky)
  2. Define explicit mappings when I create the index (a little annoying, since I find the default mappings useful and would prefer to use them)
  3. Do an additional index status request first to see if the document count is zero (has to be done on every request)
  4. Catch the exception (seems dangerous because I don't think I get the real cause (missing mapping) except as part of the message text)
  5. other ideas?

thanks,

Curtis