1

I've run into a problem while trying to sort on nested multi-field properties in Elasticsearch. One of the two multi-fields works, the other returns null for every value.

My sortable analyzer:

    "analyzer": {
        "sortable": {
            "type": "custom",
            "tokenizer": "keyword",
            "filter": ["lowercase"]
        }
    }

Mapping:

{
    "doc": {
        "properties": {
            "id" : {
                "type": "long"
            },
            "name": {
                "type": "string",
                "index": "analyzed",
                "analyzer": "snowball",
                "fields": {
                    "sortable": { 
                        "type": "string",
                        "analyzer": "sortable"
                    }
                }
            },
            "website": {
                "type": "nested",
                "properties": {
                    "domain": {
                        "type": "string",
                        "analyzer": "snowball",
                        "fields": {
                            "sortable": { 
                                "type": "string",
                                "analyzer": "sortable"
                            }
                        }
                    },
                    "created": {
                        "type": "date"
                    }
                }
            } 
        }
    }
}

A full working example is here. Note the four searches at the bottom. Sorting by name or name.sortable both show values in the sort section of the result. Sorting by website.domain shows a value in the sort section, but website.domain.sortable always shows null.

I'm hoping I'm just doing something silly here, but for the life of me I can't see what. This is in Elasticsearch 1.1.0. I'll gladly also take alternative solutions, though I hate to just slap the field in there twice under two different names.

1 Answer 1

1

You need to require a path for sorting on nested document types. http://sense.qbox.io/gist/0d05fcf12be64e4a924a6b010ffe55e72d91b147

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

5 Comments

Does that really apply though? I'm adding the "fields" to the string types underneath a nested type, not on the nested type itself. And the searching does work for both fields. If I change the search term to "mydomain-com" the snowball-analyzed field (website.domain) matches on "mydomain" or "com", while the sortable field (website.domain.sortable) only matches on the full text "mydomain-com". New samples at sense.qbox.io/gist/cc801f831b45075463ee160146aea279419d0505 And I'll gladly use sense.qbox.io, makes things much easier.
You're absolutely correct, I was doing a exists filter without the nested, so I came with the wrong conclusion. I'm looking into it now. Very strange
That absolutely worked, not sure how I missed that detail in what I swear was a thorough reading of the documentation. Many thanks.
Happens to the best of us, thanks again for using our sense thingy.
May you update the code? I can not see your gist on qbox. Thanks

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.