Matt Hintzke
Matt Hintzke

Reputation: 7984

Indexing a multi-field property in Elastic Search

I am trying to re-index my documents in order for them to be sortable which requires making the sortable fields Multi-field properties with a "raw" version of the string which does not get analyzed.

I am following this article, but I am still getting errors when searching my documents with a sorting query.

I have a question then regarding the re-indexing of the data... if I re-index the doucments into this new index, then do I need to have some extra logic to set the analyzed version and the non_analyzed or "raw" version of the string as well? Or does elastic search automatically fill that one? Here is what my field looks like:

{
    "entityName": {
        "type":"string",
        "fields": {
            "raw": {
                "type":"string",
                "index":"not_analyzed"
            }
        }
    }
}

So when I index a document with a _source like:

{
...
"entityName":"Ned Stark"
...
}

Will the mapping to both the analyzed field and the not_analyzed field complete or is there something else I have to do to tell the indexing to fill in the "raw" property as well?

Upvotes: 1

Views: 3592

Answers (1)

TautrimasPajarskas
TautrimasPajarskas

Reputation: 2796

No, you don't need to do anything else.

After reindexing your documents, you must tell which fields the query should use like in your given documentation article.

Raw subfield:

POST /_search
{
    "query": {
        "match": {
            "entityName.raw": "foo-bar"
        }
    }
}

or original analysed type:

POST /_search
{
    "query": {
        "match": {
            "entityName": "foo-bar"
        }
    }
}

Upvotes: 3

Related Questions