Sort on nested object

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

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

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:

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

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

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

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. 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

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

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

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.

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. 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

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

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

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"}
}
}
}
}
}

{
"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 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....

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...

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...

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

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

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 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"}
}
}
}
}

}

{
"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 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....

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...

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...

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

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

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

On Apr 18, 3:26 pm, Clinton Gormley 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