3

I have created the index with following setting and mapping:

PUT test

    {
        "settings": {
            "number_of_shards": 2,
            "number_of_replicas": 1
        },
        "mappings": {
            "documents": {
                "properties": {
                    "title": {
                        "type": "text",
                        "fields": {
                            "raw": {
                                "type": "keyword"
                            }
                        }
                    },
                    "url": {
                        "type": "text",
                        "fields": {
                            "raw": {
                                "type": "keyword"
                            }
                        }
                    },
                    "tags": {
                        "type": "keyword"
                    }
                }
            }
        }
    }

In above mapping, I have declared tags as type keyword for the exact match.and added 10 documents into it for example:

PUT test/documents/1
{
  "title":"John",
  "url":"/john",
  "tags":["name question","how"]
}

but I want to add multi-fields support for tags to support partial tags matching so I have updated index mapping as follows:

PUT test/documents/_mapping
{
    "properties": {
        "title": {
            "type": "text",
            "fields": {
                "raw": {
                    "type": "keyword"
                }
            }
        },
        "url": {
            "type": "text",
            "fields": {
                "raw": {
                    "type": "keyword"
                }
            }
        },
        "tags": {
            "type": "keyword",
            "fields": {
                "raw": {
                    "type": "text"
                }
            }
        }
    }
}

is this right way to updae index mapping? Can now my tags support partial matching? Please help me into this

1 Answer 1

4

Yes. That's the way to update that field. Although I'd not use raw as the name for the subfield. It's not the common to have raw as text type. I'd name it something like fulltext for example.

Anyway, even if you update the mapping you have to reindex all the documents.

Update by Query will do that:

curl -X POST "localhost:9200/test/_update_by_query?conflicts=proceed"

By the way (and not related to your question) I'd use _doc as the type name so you will be even more ready for the removal of types in the future.

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

Comments

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.