Searching an empty index with a sort field specified should not fail

Hi - In ElasticSearch 0.19.4, if we issue a search request via the Java
API against an empty index with a sort field specified, eg
searchSourceBuilder.sort("foo"), an error is returned:

...Parse Failure [No mapping found for [foo] in order to sort on]]...

Since by definition an empty index will return an empty result set, it
should not be necessary to sort it? It may be better to simply return the
empty result set in this case - having to deal with the empty index case
complicates our client code, especially in tests, where we create the index
at startup and issue search requests against the empty index which we
expect to return an empty result set.

+1 for this.
I'd like sort requests to be ignored if mapping for this field doesn't
exist yet.

There is an option to ignore unmapped fields when sorting in 0.19:
Allow search to continue when sort field is missing from type mapping · Issue #1558 · elastic/elasticsearch · GitHub.

On Tue, May 29, 2012 at 4:08 PM, Wojciech Durczyński <
wojciech.durczynski@comarch.com> wrote:

+1 for this.
I'd like sort requests to be ignored if mapping for this field doesn't
exist yet.

Awesome :slight_smile:
How could I missed it from the changelog? Thank you very much.

W dniu środa, 30 maja 2012 00:26:05 UTC+2 użytkownik kimchy napisał:

There is an option to ignore unmapped fields when sorting in 0.19:
Allow search to continue when sort field is missing from type mapping · Issue #1558 · elastic/elasticsearch · GitHub.

On Tue, May 29, 2012 at 4:08 PM, Wojciech Durczyński <
wojciech.durczynski@comarch.com> wrote:

+1 for this.
I'd like sort requests to be ignored if mapping for this field doesn't
exist yet.

Hi - ignore_unmapped is useful, but it shouldn't be necessary to specify
this option since:

a) an empty result set does not need to be sorted
b) an empty index will always return an empty result set

so it's really an optimization to ignore the query (and sort field)
entirely when searching an empty index, and simply return an empty result
set.

On Wednesday, 30 May 2012 12:02:26 UTC+1, Wojciech Durczyński wrote:

Awesome :slight_smile:
How could I missed it from the changelog? Thank you very much.

W dniu środa, 30 maja 2012 00:26:05 UTC+2 użytkownik kimchy napisał:

There is an option to ignore unmapped fields when sorting in 0.19:
Allow search to continue when sort field is missing from type mapping · Issue #1558 · elastic/elasticsearch · GitHub.

On Tue, May 29, 2012 at 4:08 PM, Wojciech Durczyński <
wojciech.durczynski@comarch.com> wrote:

+1 for this.
I'd like sort requests to be ignored if mapping for this field doesn't
exist yet.

To be honest, I am not sure whats the best solution here for an empty
index. The fact that the index does not have data does not mean that it
does not possibly have mappings defined..., and a failure should occur in
cases where you try and sort on a field that does not exists unless you
explicitly state otherwise...

On Thu, May 31, 2012 at 11:38 PM, Michael Snell michael@snell.com wrote:

Hi - ignore_unmapped is useful, but it shouldn't be necessary to specify
this option since:

a) an empty result set does not need to be sorted
b) an empty index will always return an empty result set

so it's really an optimization to ignore the query (and sort field)
entirely when searching an empty index, and simply return an empty result
set.

On Wednesday, 30 May 2012 12:02:26 UTC+1, Wojciech Durczyński wrote:

Awesome :slight_smile:
How could I missed it from the changelog? Thank you very much.

W dniu środa, 30 maja 2012 00:26:05 UTC+2 użytkownik kimchy napisał:

There is an option to ignore unmapped fields when sorting in 0.19:
https://github.com/**elasticsearch/elasticsearch/**issues/1558https://github.com/elasticsearch/elasticsearch/issues/1558
.

On Tue, May 29, 2012 at 4:08 PM, Wojciech Durczyński <
wojciech.durczynski@comarch.**com wojciech.durczynski@comarch.com>wrote:

+1 for this.
I'd like sort requests to be ignored if mapping for this field doesn't
exist yet.