1

I am trying to do sorting by "timestamp" field (which is not a "_timestamp" default). "timestamp" field stores micro-unixtime in

"_source": {
   ...
   "timestamp": "1381256450000" 
   ...
}

On screenshot you can see this value in 'sort' (right side). Last record should be definitely on the top of the result. But it isn't.

Screenshot: ESquery

5
  • it comes from a different index. are the records returned sorted within their index only? Commented Oct 15, 2013 at 8:56
  • Is timestamp in the index mapping ? Commented Oct 15, 2013 at 9:14
  • @phoet no they are not, you can see it in first 3 records on screenshot Commented Oct 15, 2013 at 9:28
  • @Co_42 I guess it is not, I am trying to use the simple sorting by field. Commented Oct 15, 2013 at 9:28
  • There is indeed something wrong here but I wouldn't say "sorting in elasticsearch doesn't work" otherwise there would be quite some unhappy users :) Can you maybe post curl commands and json instead of screenshots? Maybe a full curl recreation with a few docs too? Commented Oct 15, 2013 at 17:16

1 Answer 1

1

From elasticsearch website :

By default, the search request will fail if there is no mapping associated with a field. The ignore_unmapped option allows to ignore fields that have no mapping and not sort by them.

You have to map the field if you want to use it to sort the results.

Sign up to request clarification or add additional context in comments.

3 Comments

could you provide an example? Is it possible to include it in search query or I should set it permanently?
The following 2 links explain how to set the index mapping : elasticsearch.org/guide/en/elasticsearch/reference/current/… elasticsearch.org/guide/en/elasticsearch/reference/current/… The mapping is set permanently and you have to re-index all your existing documents.
If a field appears in at least a document, it gets automatically submitted in the mapping with sensible defaults. If you try to sort on an unmapped field, you get back an error. Say that you query multiple types and one of them doesn't have the field (it never appeared in any document and you haven't submitted its mapping manually), then you get an error. It doesn't seem to be the case here?

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.