# Sort on nested object

**URL:** <https://discuss.elastic.co/t/sort-on-nested-object/6874>\
**Category:** Elasticsearch\
**Created:** [March 4, 2012, 2:32am UTC](https://discuss.elastic.co/t/sort-on-nested-object/6874 "2012-03-04T02:32:50Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![Arny](https://avatars.discourse-cdn.com/v4/letter/a/8dc957/32.png) [@Arny](https://discuss.elastic.co/u/Arny)\
**Post date:** [March 4, 2012, 2:32am UTC](https://discuss.elastic.co/t/sort-on-nested-object/6874/1 "2012-03-04T02:32:50Z")

</div>

Hi,

well, I've read all the other "sort on nested" threads, but I kind of need  
a solution for my issue.

I'm using something like:  
{ \_id: "..",  
someGlobalInfo: "foo",  
localizedInfo: { DE: { title: "foo" },  
{ UK: { title: "foo" } }  
}

I'd like to have a document with localized data, but also be able to sort  
on that.  
Using Java over here.  
Not sure why sorting on localizedInfo.DE.title is detected as field with  
multiple values. It's actually very unique.

Thanks

---

<div class="post-metadata">

**Author:** ![Arny](https://avatars.discourse-cdn.com/v4/letter/a/8dc957/32.png) [@Arny](https://discuss.elastic.co/u/Arny)\
**Post date:** [March 4, 2012, 3:52am UTC](https://discuss.elastic.co/t/sort-on-nested-object/6874/2 "2012-03-04T03:52:11Z")

</div>

Strange thing is: sorting on float type works. But why not string?  
My mapping on that field: ...startObject("localizedInfo").field("type",  
"object").endObject()

Is this a bug?  
I'm using 0.19.0.

Am Sonntag, 4. März 2012 03:32:50 UTC+1 schrieb Arny:

> Hi,
> 
> well, I've read all the other "sort on nested" threads, but I kind of need  
> a solution for my issue.
> 
> I'm using something like:  
> { \_id: "..",  
> someGlobalInfo: "foo",  
> localizedInfo: { DE: { title: "foo" },  
> { UK: { title: "foo" } }  
> }
> 
> I'd like to have a document with localized data, but also be able to sort  
> on that.  
> Using Java over here.  
> Not sure why sorting on localizedInfo.DE.title is detected as field with  
> multiple values. It's actually very unique.
> 
> Thanks

---

<div class="post-metadata">

**Author:** ![Clinton\_Gormley](https://avatars.discourse-cdn.com/v4/letter/c/50afbb/32.png) [@Clinton\_Gormley](https://discuss.elastic.co/u/Clinton_Gormley)\
**Post date:** [March 4, 2012, 8:17am UTC](https://discuss.elastic.co/t/sort-on-nested-object/6874/3 "2012-03-04T08:17:13Z")

</div>

Hiya

> well, I've read all the other "sort on nested" threads, but I kind of  
> need a solution for my issue.
> 
> I'm using something like:  
> { \_id: "..",  
> someGlobalInfo: "foo",  
> localizedInfo: { DE: { title: "foo" },  
> { UK: { title: "foo" } }  
> }

Have a read of this:

> <https://stackoverflow.com/questions/9535016/is-it-possible-to-sort-nested-documents-in-elasticsearch>

> 

clint

> I'd like to have a document with localized data, but also be able to  
> sort on that.  
> Using Java over here.  
> Not sure why sorting on localizedInfo.DE.title is detected as field  
> with multiple values. It's actually very unique.
> 
> Thanks

---

<div class="post-metadata">

**Author:** ![Arny](https://avatars.discourse-cdn.com/v4/letter/a/8dc957/32.png) [@Arny](https://discuss.elastic.co/u/Arny)\
**Post date:** [March 4, 2012, 9:22pm UTC](https://discuss.elastic.co/t/sort-on-nested-object/6874/4 "2012-03-04T21:22:41Z")

</div>

Thanks, I've seen that as well.

But, why is sorting:

> localizedInfo.DE.someFloat  
> working ?  
> localizedInfo.DE.someString  
> is not working ?  
> Both are unique, there are no multiple values per field.

Mapping is dynamically mapped to type "string".

Whats the problem here?

Am Sonntag, 4. März 2012 09:17:13 UTC+1 schrieb Clinton Gormley:

> Hiya
> 
> > well, I've read all the other "sort on nested" threads, but I kind of  
> > need a solution for my issue.
> > 
> > I'm using something like:  
> > { \_id: "..",  
> > someGlobalInfo: "foo",  
> > localizedInfo: { DE: { title: "foo" },  
> > { UK: { title: "foo" } }  
> > }
> 
> Have a read of this:
> 
> [Is it possible to sort nested documents in ElasticSearch? - Stack Overflow](http://stackoverflow.com/questions/9535016/is-it-possible-to-sort-nested-documents-in-elasticsearch)
> 
> > 
> 
> clint
> 
> > I'd like to have a document with localized data, but also be able to  
> > sort on that.  
> > Using Java over here.  
> > Not sure why sorting on localizedInfo.DE.title is detected as field  
> > with multiple values. It's actually very unique.
> > 
> > Thanks

---

<div class="post-metadata">

**Author:** ![Mark\_Waddle](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mark_waddle/32/2608_2.png) [@Mark\_Waddle](https://discuss.elastic.co/u/Mark_Waddle)\
**Post date:** [March 5, 2012, 6:53am UTC](https://discuss.elastic.co/t/sort-on-nested-object/6874/5 "2012-03-05T06:53:15Z")

</div>

Hi Arn,

I think that strings are analyzed by default, and therefore if you have  
titles with multiple words they will be split into multiple terms, and  
therefore be considered a multi-valued field. As you can imagine this is  
beneficial for searching because a search for any of the terms will hit on  
the title field. However, to work well with sorting, or faceting for that  
matter, you need to change the mapping so that it is not analyzed {  
"index":"not\_analyzed"}. See  
[Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/mapping/core-types.html). If  
you need an analyzed field for searching and a not\_analyzed field for  
sorting, you will need two fields with the same data.

Mark

On Sunday, March 4, 2012 1:22:41 PM UTC-8, Arny wrote:

> Thanks, I've seen that as well.
> 
> But, why is sorting:
> 
> > localizedInfo.DE.someFloat  
> > working ?  
> > localizedInfo.DE.someString  
> > is not working ?  
> > Both are unique, there are no multiple values per field.
> 
> Mapping is dynamically mapped to type "string".
> 
> Whats the problem here?
> 
> Am Sonntag, 4. März 2012 09:17:13 UTC+1 schrieb Clinton Gormley:
> 
> > Hiya
> > 
> > > well, I've read all the other "sort on nested" threads, but I kind of  
> > > need a solution for my issue.
> > > 
> > > I'm using something like:  
> > > { \_id: "..",  
> > > someGlobalInfo: "foo",  
> > > localizedInfo: { DE: { title: "foo" },  
> > > { UK: { title: "foo" } }  
> > > }
> > 
> > Have a read of this:
> > 
> > [Is it possible to sort nested documents in ElasticSearch? - Stack Overflow](http://stackoverflow.com/questions/9535016/is-it-possible-to-sort-nested-documents-in-elasticsearch)
> > 
> > > 
> > 
> > clint
> > 
> > > I'd like to have a document with localized data, but also be able to  
> > > sort on that.  
> > > Using Java over here.  
> > > Not sure why sorting on localizedInfo.DE.title is detected as field  
> > > with multiple values. It's actually very unique.
> > > 
> > > Thanks

On Sunday, March 4, 2012 1:22:41 PM UTC-8, Arny wrote:

> Thanks, I've seen that as well.
> 
> But, why is sorting:
> 
> > localizedInfo.DE.someFloat  
> > working ?  
> > localizedInfo.DE.someString  
> > is not working ?  
> > Both are unique, there are no multiple values per field.
> 
> Mapping is dynamically mapped to type "string".
> 
> Whats the problem here?
> 
> Am Sonntag, 4. März 2012 09:17:13 UTC+1 schrieb Clinton Gormley:
> 
> > Hiya
> > 
> > > well, I've read all the other "sort on nested" threads, but I kind of  
> > > need a solution for my issue.
> > > 
> > > I'm using something like:  
> > > { \_id: "..",  
> > > someGlobalInfo: "foo",  
> > > localizedInfo: { DE: { title: "foo" },  
> > > { UK: { title: "foo" } }  
> > > }
> > 
> > Have a read of this:
> > 
> > [Is it possible to sort nested documents in ElasticSearch? - Stack Overflow](http://stackoverflow.com/questions/9535016/is-it-possible-to-sort-nested-documents-in-elasticsearch)
> > 
> > > 
> > 
> > clint
> > 
> > > I'd like to have a document with localized data, but also be able to  
> > > sort on that.  
> > > Using Java over here.  
> > > Not sure why sorting on localizedInfo.DE.title is detected as field  
> > > with multiple values. It's actually very unique.
> > > 
> > > Thanks

---

<div class="post-metadata">

**Author:** ![kimchy](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kimchy/32/44952_2.png) [@kimchy](https://discuss.elastic.co/u/kimchy)\
**Post date:** [March 5, 2012, 3:16pm UTC](https://discuss.elastic.co/t/sort-on-nested-object/6874/6 "2012-03-05T15:16:47Z")

</div>

Note that you don't have to have two fields with the same data to have an analyzed version and a non analyzed version. You can use the multi field mapping on the same "json field". see more here: [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/mapping/multi-field-type.html).

On Monday, March 5, 2012 at 8:53 AM, Mark Waddle wrote:

> Hi Arn,
> 
> I think that strings are analyzed by default, and therefore if you have titles with multiple words they will be split into multiple terms, and therefore be considered a multi-valued field. As you can imagine this is beneficial for searching because a search for any of the terms will hit on the title field. However, to work well with sorting, or faceting for that matter, you need to change the mapping so that it is not analyzed { "index":"not\_analyzed"}. See [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/mapping/core-types.html). If you need an analyzed field for searching and a not\_analyzed field for sorting, you will need two fields with the same data.
> 
> Mark
> 
> On Sunday, March 4, 2012 1:22:41 PM UTC-8, Arny wrote:
> 
> > Thanks, I've seen that as well.
> > 
> > But, why is sorting:
> > 
> > > localizedInfo.DE.someFloat  
> > > working ?  
> > > localizedInfo.DE.someString  
> > > is not working ?  
> > > Both are unique, there are no multiple values per field.
> > 
> > Mapping is dynamically mapped to type "string".
> > 
> > Whats the problem here?
> > 
> > Am Sonntag, 4. März 2012 09:17:13 UTC+1 schrieb Clinton Gormley:
> > 
> > > Hiya
> > > 
> > > > well, I've read all the other "sort on nested" threads, but I kind of  
> > > > need a solution for my issue.
> > > > 
> > > > I'm using something like:  
> > > > { \_id: "..",  
> > > > someGlobalInfo: "foo",  
> > > > localizedInfo: { DE: { title: "foo" },  
> > > > { UK: { title: "foo" } }  
> > > > }  
> > > > Have a read of this:  
> > > > [Is it possible to sort nested documents in ElasticSearch? - Stack Overflow](http://stackoverflow.com/questions/9535016/is-it-possible-to-sort-nested-documents-in-elasticsearch)
> > > 
> > > clint
> > > 
> > > > I'd like to have a document with localized data, but also be able to  
> > > > sort on that.  
> > > > Using Java over here.  
> > > > Not sure why sorting on localizedInfo.DE.title is detected as field  
> > > > with multiple values. It's actually very unique.
> > > > 
> > > > Thanks
> 
> On Sunday, March 4, 2012 1:22:41 PM UTC-8, Arny wrote:
> 
> > Thanks, I've seen that as well.
> > 
> > But, why is sorting:
> > 
> > > localizedInfo.DE.someFloat  
> > > working ?  
> > > localizedInfo.DE.someString  
> > > is not working ?  
> > > Both are unique, there are no multiple values per field.
> > 
> > Mapping is dynamically mapped to type "string".
> > 
> > Whats the problem here?
> > 
> > Am Sonntag, 4. März 2012 09:17:13 UTC+1 schrieb Clinton Gormley:
> > 
> > > Hiya
> > > 
> > > > well, I've read all the other "sort on nested" threads, but I kind of  
> > > > need a solution for my issue.
> > > > 
> > > > I'm using something like:  
> > > > { \_id: "..",  
> > > > someGlobalInfo: "foo",  
> > > > localizedInfo: { DE: { title: "foo" },  
> > > > { UK: { title: "foo" } }  
> > > > }  
> > > > Have a read of this:  
> > > > [Is it possible to sort nested documents in ElasticSearch? - Stack Overflow](http://stackoverflow.com/questions/9535016/is-it-possible-to-sort-nested-documents-in-elasticsearch)
> > > 
> > > clint
> > > 
> > > > I'd like to have a document with localized data, but also be able to  
> > > > sort on that.  
> > > > Using Java over here.  
> > > > Not sure why sorting on localizedInfo.DE.title is detected as field  
> > > > with multiple values. It's actually very unique.
> > > > 
> > > > Thanks

---

<div class="post-metadata">

**Author:** ![Alexander\_Soudakov](https://avatars.discourse-cdn.com/v4/letter/a/f08c70/32.png) [@Alexander\_Soudakov](https://discuss.elastic.co/u/Alexander_Soudakov)\
**Post date:** [April 17, 2012, 1:05pm UTC](https://discuss.elastic.co/t/sort-on-nested-object/6874/7 "2012-04-17T13:05:38Z")

</div>

Hi.

But how can I define multi\_field for nested field? Considering your  
answer above it's possible.  
Let's assume following simple structure:  
{  
"name": "NAME",  
"city": {  
"name": "CITY",  
"id": 1  
}  
}  
I've tried 2 variants:  
1.  
{  
"mytype" : {  
"properties" : {  
"city.name" : {  
"type" : "multi\_field",  
"fields" : {  
"name" : {"type" : "string", "index" :  
"analyzed"},  
"untouched" : {"type" : "string", "index" :  
"not\_analyzed"}  
}  
}  
}  
}  
}

1. 

{  
"mytype" : {  
"properties" : {  
"city.name" : {  
"type" : "multi\_field",  
"fields" : {  
"city.name" : {"type" : "string", "index" :  
"analyzed"},  
"city.name.untouched" : {"type" : "string",  
"index" : "not\_analyzed"}  
}  
}  
}  
}  
}

Both worked and allow me to search for "city.name" "CITY" but with no  
hits in results.  
Also sorting doesn't works well: sort value for each hit is null and  
sorting is wrong.

How to defined multi\_field for nested field correctly?

On Mar 5, 10:16 pm, Shay Banon [kim...@gmail.com](mailto:kim...@gmail.com) wrote:

> Note that you don't have to have two fields with the same data to have an analyzed version and a non analyzed version. You can use the multi field mapping on the same "json field". see more here:[Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/mapping/multi-field-type)....
> 
> On Monday, March 5, 2012 at 8:53 AM, Mark Waddle wrote:
> 
> > Hi Arn,
> 
> > I think that strings are analyzed by default, and therefore if you have titles with multiple words they will be split into multiple terms, and therefore be considered a multi-valued field. As you can imagine this is beneficial for searching because a search for any of the terms will hit on the title field. However, to work well with sorting, or faceting for that matter, you need to change the mapping so that it is not analyzed { "index":"not\_analyzed"}. Seehttp://www.elasticsearch.org/guide/reference/mapping/core-types.html. If you need an analyzed field for searching and a not\_analyzed field for sorting, you will need two fields with the same data.
> 
> > Mark
> 
> > On Sunday, March 4, 2012 1:22:41 PM UTC-8, Arny wrote:
> > 
> > > Thanks, I've seen that as well.
> 
> > > But, why is sorting:
> > > 
> > > > localizedInfo.DE.someFloat  
> > > > working ?  
> > > > localizedInfo.DE.someString  
> > > > is not working ?  
> > > > Both are unique, there are no multiple values per field.
> 
> > > Mapping is dynamically mapped to type "string".
> 
> > > Whats the problem here?
> 
> > > Am Sonntag, 4. März 2012 09:17:13 UTC+1 schrieb Clinton Gormley:
> > > 
> > > > Hiya
> > > > 
> > > > > well, I've read all the other "sort on nested" threads, but I kind of  
> > > > > need a solution for my issue.
> 
> > > > > I'm using something like:  
> > > > > { \_id: "..",  
> > > > > someGlobalInfo: "foo",  
> > > > > localizedInfo: { DE: { title: "foo" },  
> > > > > { UK: { title: "foo" } }  
> > > > > }  
> > > > > Have a read of this:  
> > > > > [Is it possible to sort nested documents in ElasticSearch? - Stack Overflow](http://stackoverflow.com/questions/9535016/is-it-possible-to-sort-nes)...
> 
> > > > clint
> 
> > > > > I'd like to have a document with localized data, but also be able to  
> > > > > sort on that.  
> > > > > Using Java over here.  
> > > > > Not sure why sorting on localizedInfo.DE.title is detected as field  
> > > > > with multiple values. It's actually very unique.
> 
> > > > > Thanks
> 
> > On Sunday, March 4, 2012 1:22:41 PM UTC-8, Arny wrote:
> > 
> > > Thanks, I've seen that as well.
> 
> > > But, why is sorting:
> > > 
> > > > localizedInfo.DE.someFloat  
> > > > working ?  
> > > > localizedInfo.DE.someString  
> > > > is not working ?  
> > > > Both are unique, there are no multiple values per field.
> 
> > > Mapping is dynamically mapped to type "string".
> 
> > > Whats the problem here?
> 
> > > Am Sonntag, 4. März 2012 09:17:13 UTC+1 schrieb Clinton Gormley:
> > > 
> > > > Hiya
> > > > 
> > > > > well, I've read all the other "sort on nested" threads, but I kind of  
> > > > > need a solution for my issue.
> 
> > > > > I'm using something like:  
> > > > > { \_id: "..",  
> > > > > someGlobalInfo: "foo",  
> > > > > localizedInfo: { DE: { title: "foo" },  
> > > > > { UK: { title: "foo" } }  
> > > > > }  
> > > > > Have a read of this:  
> > > > > [Is it possible to sort nested documents in ElasticSearch? - Stack Overflow](http://stackoverflow.com/questions/9535016/is-it-possible-to-sort-nes)...
> 
> > > > clint
> 
> > > > > I'd like to have a document with localized data, but also be able to  
> > > > > sort on that.  
> > > > > Using Java over here.  
> > > > > Not sure why sorting on localizedInfo.DE.title is detected as field  
> > > > > with multiple values. It's actually very unique.
> 
> > > > > Thanks

---

<div class="post-metadata">

**Author:** ![Alexander\_Soudakov](https://avatars.discourse-cdn.com/v4/letter/a/f08c70/32.png) [@Alexander\_Soudakov](https://discuss.elastic.co/u/Alexander_Soudakov)\
**Post date:** [April 18, 2012, 3:01am UTC](https://discuss.elastic.co/t/sort-on-nested-object/6874/8 "2012-04-18T03:01:57Z")

</div>

Ok, I searched this group more and found this:  
[https://groups.google.com/group/elasticsearch/browse\_thread/thread/239e827372713878/52ab82483097e094?lnk=gst&q=sort+on+nested#52ab82483097e094](https://groups.google.com/group/elasticsearch/browse_thread/thread/239e827372713878/52ab82483097e094?lnk=gst&q=sort+on+nested#52ab82483097e094)

So I can't sort on nested fields...  
Which is strange, because in my example above:  
{  
"name": "NAME",  
"city": {  
"name": "CITY",  
"id": 1  
}  
}

It really sorts data on "city.id" - I see proper values in sort: [...]  
in returned hits.  
With string type I want to use multi\_field "trick".  
Let me know if it's possible or I'll need to rename that fields to  
"top level" ones.

On Apr 17, 8:05 pm, Alexander Soudakov [c...@blockshopper.com](mailto:c...@blockshopper.com) wrote:

> Hi.
> 
> But how can I definemulti\_fieldfornestedfield? Considering your  
> answer above it's possible.  
> Let's assume following simple structure:  
> {  
> "name": "NAME",  
> "city": {  
> "name": "CITY",  
> "id": 1  
> }}
> 
> I've tried 2 variants:  
> 1.  
> {  
> "mytype" : {  
> "properties" : {  
> "city.name" : {  
> "type" : "multi\_field",  
> "fields" : {  
> "name" : {"type" : "string", "index" :  
> "analyzed"},  
> "untouched" : {"type" : "string", "index" :  
> "not\_analyzed"}  
> }  
> }  
> }  
> }
> 
> }
> 
> 1. 
> 
> {  
> "mytype" : {  
> "properties" : {  
> "city.name" : {  
> "type" : "multi\_field",  
> "fields" : {  
> "city.name" : {"type" : "string", "index" :  
> "analyzed"},  
> "city.name.untouched" : {"type" : "string",  
> "index" : "not\_analyzed"}  
> }  
> }  
> }  
> }
> 
> }
> 
> Both worked and allow me to search for "city.name" "CITY" but with no  
> hits in results.  
> Also sorting doesn't works well: sort value for each hit is null and  
> sorting is wrong.
> 
> How to definedmulti\_fieldfornestedfieldcorrectly?
> 
> On Mar 5, 10:16 pm, Shay Banon [kim...@gmail.com](mailto:kim...@gmail.com) wrote:
> 
> > Note that you don't have to have two fields with the same data to have an analyzed version and a non analyzed version. You can use the multifieldmapping on the same "jsonfield". see more here:[Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/mapping/multi-field-type)....
> 
> > On Monday, March 5, 2012 at 8:53 AM, Mark Waddle wrote:
> > 
> > > Hi Arn,
> 
> > > I think that strings are analyzed by default, and therefore if you have titles with multiple words they will be split into multiple terms, and therefore be considered a multi-valuedfield. As you can imagine this is beneficial for searching because a search for any of the terms will hit on the titlefield. However, to work well with sorting, or faceting for that matter, you need to change the mapping so that it is not analyzed { "index":"not\_analyzed"}. Seehttp://www.elasticsearch.org/guide/reference/mapping/core-types.html. If you need an analyzedfieldfor searching and a not\_analyzedfieldfor sorting, you will need two fields with the same data.
> 
> > > Mark
> 
> > > On Sunday, March 4, 2012 1:22:41 PM UTC-8, Arny wrote:
> > > 
> > > > Thanks, I've seen that as well.
> 
> > > > But, why is sorting:
> > > > 
> > > > > localizedInfo.DE.someFloat  
> > > > > working ?  
> > > > > localizedInfo.DE.someString  
> > > > > is not working ?  
> > > > > Both are unique, there are no multiple values perfield.
> 
> > > > Mapping is dynamically mapped to type "string".
> 
> > > > Whats the problem here?
> 
> > > > Am Sonntag, 4. März 2012 09:17:13 UTC+1 schrieb Clinton Gormley:
> > > > 
> > > > > Hiya
> > > > > 
> > > > > > well, I've read all the other "sort onnested" threads, but I kind of  
> > > > > > need a solution for my issue.
> 
> > > > > > I'm using something like:  
> > > > > > { \_id: "..",  
> > > > > > someGlobalInfo: "foo",  
> > > > > > localizedInfo: { DE: { title: "foo" },  
> > > > > > { UK: { title: "foo" } }  
> > > > > > }  
> > > > > > Have a read of this:  
> > > > > > [Is it possible to sort nested documents in ElasticSearch? - Stack Overflow](http://stackoverflow.com/questions/9535016/is-it-possible-to-sort-nes)...
> 
> > > > > clint
> 
> > > > > > I'd like to have a document with localized data, but also be able to  
> > > > > > sort on that.  
> > > > > > Using Java over here.  
> > > > > > Not sure why sorting on localizedInfo.DE.title is detected asfield  
> > > > > > with multiple values. It's actually very unique.
> 
> > > > > > Thanks
> 
> > > On Sunday, March 4, 2012 1:22:41 PM UTC-8, Arny wrote:
> > > 
> > > > Thanks, I've seen that as well.
> 
> > > > But, why is sorting:
> > > > 
> > > > > localizedInfo.DE.someFloat  
> > > > > working ?  
> > > > > localizedInfo.DE.someString  
> > > > > is not working ?  
> > > > > Both are unique, there are no multiple values perfield.
> 
> > > > Mapping is dynamically mapped to type "string".
> 
> > > > Whats the problem here?
> 
> > > > Am Sonntag, 4. März 2012 09:17:13 UTC+1 schrieb Clinton Gormley:
> > > > 
> > > > > Hiya
> > > > > 
> > > > > > well, I've read all the other "sort onnested" threads, but I kind of  
> > > > > > need a solution for my issue.
> 
> > > > > > I'm using something like:  
> > > > > > { \_id: "..",  
> > > > > > someGlobalInfo: "foo",  
> > > > > > localizedInfo: { DE: { title: "foo" },  
> > > > > > { UK: { title: "foo" } }  
> > > > > > }  
> > > > > > Have a read of this:  
> > > > > > [Is it possible to sort nested documents in ElasticSearch? - Stack Overflow](http://stackoverflow.com/questions/9535016/is-it-possible-to-sort-nes)...
> 
> > > > > clint
> 
> > > > > > I'd like to have a document with localized data, but also be able to  
> > > > > > sort on that.  
> > > > > > Using Java over here.  
> > > > > > Not sure why sorting on localizedInfo.DE.title is detected asfield  
> > > > > > with multiple values. It's actually very unique.
> 
> > > > > > Thanks

---

<div class="post-metadata">

**Author:** ![Clinton\_Gormley](https://avatars.discourse-cdn.com/v4/letter/c/50afbb/32.png) [@Clinton\_Gormley](https://discuss.elastic.co/u/Clinton_Gormley)\
**Post date:** [April 18, 2012, 8:26am UTC](https://discuss.elastic.co/t/sort-on-nested-object/6874/9 "2012-04-18T08:26:14Z")

</div>

Hiya

> {  
> "mytype" : {  
> "properties" : {  
> "city.name" : {  
> "type" : "multi\_field",  
> "fields" : {  
> "name" : {"type" : "string", "index" :  
> "analyzed"},  
> "untouched" : {"type" : "string", "index" :  
> "not\_analyzed"}  
> }  
> }  
> }  
> }  
> }

You can't name your fields with a dot in them (ie "city.name").

> Which is strange, because in my example above:  
> {  
> "name": "NAME",  
> "city": {  
> "name": "CITY",  
> "id": 1  
> }  
> }

Try this mapping instead:

```
    "properties": {
        "name": { "type": "string" },
        "city": {
            "type": "object",
            "properties": {
                "id": { "type": "integer"},
                "name": {
                    "type": "multi_field",
                    "fields": {
                        "name": {
                            "type": "string"
                        },
                        "untouched": {
                            "type": "string",
                            "index": "not_analyzed"
                        }
                    }
            }        
            }            
        }
    }   

```

In the above example, referring to field 'city.name' will actually refer  
to 'city.name.name'. To sort on the untouched version, you should sort  
on the field 'city.name.untouched'

clint

---

<div class="post-metadata">

**Author:** ![Alexander\_Soudakov](https://avatars.discourse-cdn.com/v4/letter/a/f08c70/32.png) [@Alexander\_Soudakov](https://discuss.elastic.co/u/Alexander_Soudakov)\
**Post date:** [April 18, 2012, 9:11am UTC](https://discuss.elastic.co/t/sort-on-nested-object/6874/10 "2012-04-18T09:11:45Z")

</div>

Yes, it works.  
And make much more sense than my attempts 🙂  
Thanks.

On Apr 18, 3:26 pm, Clinton Gormley [cl...@traveljury.com](mailto:cl...@traveljury.com) wrote:

> Hiya
> 
> > {  
> > "mytype" : {  
> > "properties" : {  
> > "city.name" : {  
> > "type" : "multi\_field",  
> > "fields" : {  
> > "name" : {"type" : "string", "index" :  
> > "analyzed"},  
> > "untouched" : {"type" : "string", "index" :  
> > "not\_analyzed"}  
> > }  
> > }  
> > }  
> > }  
> > }
> 
> You can't name your fields with a dot in them (ie "city.name").
> 
> > Which is strange, because in my example above:  
> > {  
> > "name": "NAME",  
> > "city": {  
> > "name": "CITY",  
> > "id": 1  
> > }  
> > }
> 
> Try this mapping instead:
> 
> ```
> "properties": {
> "name": { "type": "string" },
> "city": {
> "type": "object",
> "properties": {
> "id": { "type": "integer"},
> "name": {
> "type": "multi_field",
> "fields": {
> "name": {
> "type": "string"
> },
> "untouched": {
> "type": "string",
> "index": "not_analyzed"
> }
> }
> }
> }
> }
> }
> 
> ```
> 
> In the above example, referring tofield'city.name' will actually refer  
> to 'city.name.name'. To sort on the untouched version, you should sort  
> on thefield'city.name.untouched'
> 
> clint

---

<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, 3:32am UTC](https://discuss.elastic.co/t/sort-on-nested-object/6874/11 "2017-07-06T03:32:08Z")

</div>


