# Strange behavior of sort on unmapped field

**URL:** <https://discuss.elastic.co/t/strange-behavior-of-sort-on-unmapped-field/15028>\
**Category:** Elasticsearch\
**Created:** [December 27, 2013, 8:14am UTC](https://discuss.elastic.co/t/strange-behavior-of-sort-on-unmapped-field/15028 "2013-12-27T08:14:59Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![aldm](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/aldm/32/45644_2.png) [@aldm](https://discuss.elastic.co/u/aldm)\
**Post date:** [December 27, 2013, 8:14am UTC](https://discuss.elastic.co/t/strange-behavior-of-sort-on-unmapped-field/15028/1 "2013-12-27T08:14:59Z")

</div>

Hi,

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 [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/23a102cb-d34f-45c6-a1df-f663991ba423%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/23a102cb-d34f-45c6-a1df-f663991ba423%40googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [July 6, 2017, 1:59am UTC](https://discuss.elastic.co/t/strange-behavior-of-sort-on-unmapped-field/15028/2 "2017-07-06T01:59:19Z")

</div>


