Strange behavior of sort on unmapped field

(aldm) #1


I'm using elasticsearch script sort and having some problems. I' working on
unmapped field with query:

{"script" : "types.contains(doc['_type'].value) ? doc['popularity'].value :
0", "order" : "desc", "type" : "number", "params" : {"types" : ["type1"]}

So this works fine except one strange issue:
Some documents doesn't have 'popularity' property (it's mapped but it's
missing from document). Some of those documents are shown in result and
some doesn't and query is partially failed but again return results. I
workaround this issue with another condition

doc['popularity'].empty ? 0 : doc['popularity'].value,

but I would still like to know why this strange behavior is happening.

Now I would like to know why all documents with missing 'popularity'
property are not handled same (some are in result set and some of them
missing from result set)?

You received this message because you are subscribed to the Google Groups "elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send an email to
To view this discussion on the web visit
For more options, visit

(system) #2