# Changing mappings of some group of ids without affecting other documents

**URL:** <https://discuss.elastic.co/t/changing-mappings-of-some-group-of-ids-without-affecting-other-documents/25410>\
**Category:** Elasticsearch\
**Created:** [July 13, 2015, 5:09am UTC](https://discuss.elastic.co/t/changing-mappings-of-some-group-of-ids-without-affecting-other-documents/25410 "2015-07-13T05:09:08Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![apanimesh061](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/apanimesh061/32/927_2.png) [@apanimesh061](https://discuss.elastic.co/u/apanimesh061)\
**Post date:** [July 13, 2015, 5:09am UTC](https://discuss.elastic.co/t/changing-mappings-of-some-group-of-ids-without-affecting-other-documents/25410/1 "2015-07-13T05:09:08Z")

</div>

I have document sets that have their own `id`s. Each document set has some documents that have their `id`s. I am trying to figure out a way to update the mapping of all documents of a set without affecting the mappings of the documents that belong to other sets. By updating I mean to add custom analyzers to the fields. There analyzers are defined in the settings. For this I got a suggestion of using shared `types` like this:

```
PUT /test_index/
{
  "settings": {
    "index.store.type": "default",
    "index": {
        "number_of_shards": 5,
        "number_of_replicas": 1,
        "refresh_interval": "60s"
    },
    "analysis": {
        "filter": {
            "porter_stemmer_en_EN": {
                "type": "stemmer",
                "name": "porter"
            },
            "default_stop_name_en_EN": {
                "type": "stop",
                "name": "_english_"
            },
            "snowball_stop_words_en_EN": {
                "type": "stop",
                "stopwords_path": "snowball.stop"
            },
            "smart_stop_words_en_EN": {
                "type": "stop",
                "stopwords_path": "smart.stop"
            },
            "shingle_filter_en_EN": {
                "type": "shingle",
                "min_shingle_size": "2",
                "max_shingle_size": "2",
                "output_unigrams": true
            }
        }
    }
  }
}

PUT /my-index/document_set/_mapping
{
  "properties": {
    "type": {
      "type": "string",
      "index": "not_analyzed"
    },
    "doc_id": {
      "type": "string",
      "index": "not_analyzed"
    },
    "plain_text": {
      "type": "string",
      "store": true,
      "index": "analyzed"
    },
    "pdf_text": {
      "type": "attachment",
      "fields": {
        "pdf_text": {
          "type": "string",
          "store": true,
          "index": "analyzed"
        }
      }
    }
  }
}

POST /my-index/document_set/1
{
  "type": "d1",
  "doc_id": "1",
  "plain_text": "simple text for doc1."
}

POST /my-index/document_set/2
{
  "type": "d1",
  "doc_id": "2",
  "pdf_text": "cGRmIHRleHQgaXMgaGVyZS4="
}

POST /my-index/document_set/3
{
  "type": "d2",
  "doc_id": "3",
  "plain_text": "simple text for doc3 in d2."
}

POST /my-index/document_set/4
{
  "type": "d2",
  "doc_id": "4",
  "pdf_text": "cGRmIHRleHQgaXMgaGVyZSBpbiBkMi4="
}

// To get documents grouped by their document set ids
GET /my-index/document_set/_search
{
  "query" : {
    "filtered" : {
      "filter" : {
        "term" : {
          "type" : "d1"
        }
      }
    }
  }
}

```

Now I have 4 documents where document 1,2 are in group d1 and document 3,4 are in d2. How can I update the mapping only for one group without affecting the other group's mapping. I can get the documents per group using the search query given in the end.

There can 1000 of such document sets having ~10000 documents.

Any help/suggestion would be appreciated.

---

<div class="post-metadata">

**Author:** ![warkolm](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/warkolm/32/39224_2.png) [@warkolm](https://discuss.elastic.co/u/warkolm)\
**Post date:** [July 13, 2015, 6:26am UTC](https://discuss.elastic.co/t/changing-mappings-of-some-group-of-ids-without-affecting-other-documents/25410/2 "2015-07-13T06:26:45Z")

</div>

You can't because they are both of the same `_type`.  
You need to reindex.

---

<div class="post-metadata">

**Author:** ![apanimesh061](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/apanimesh061/32/927_2.png) [@apanimesh061](https://discuss.elastic.co/u/apanimesh061)\
**Post date:** [July 13, 2015, 6:42am UTC](https://discuss.elastic.co/t/changing-mappings-of-some-group-of-ids-without-affecting-other-documents/25410/3 "2015-07-13T06:42:17Z")

</div>

So what should I be doing in this situation?

I thought of creating aliases for each of the document sets but updating settings for any of the aliases results in update of settings for all aliases.

Should I be going with creating separate index for all sets? Is there a limit to no. of indices?

---

<div class="post-metadata">

**Author:** ![warkolm](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/warkolm/32/39224_2.png) [@warkolm](https://discuss.elastic.co/u/warkolm)\
**Post date:** [July 13, 2015, 6:46am UTC](https://discuss.elastic.co/t/changing-mappings-of-some-group-of-ids-without-affecting-other-documents/25410/4 "2015-07-13T06:46:56Z")

</div>

Again, this is because they are the same `_type`.

It'd be easier to put them into their own index, especially since ES 2.0 will remove the ability to have multiple `_types` in the same index.

---

<div class="post-metadata">

**Author:** ![apanimesh061](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/apanimesh061/32/927_2.png) [@apanimesh061](https://discuss.elastic.co/u/apanimesh061)\
**Post date:** [July 13, 2015, 6:53am UTC](https://discuss.elastic.co/t/changing-mappings-of-some-group-of-ids-without-affecting-other-documents/25410/5 "2015-07-13T06:53:52Z")

</div>

Ok I'll make separate index for all types.

You mean `multi_field` will be removed in the next release?

Is there any limit on the no. of indices? The application that I am working on does not a lot of query volumes/requests. So, if I keep ~10000 indices which will have a total of ~15 Million documents, is there anything I should keep in mind?

---

<div class="post-metadata">

**Author:** ![warkolm](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/warkolm/32/39224_2.png) [@warkolm](https://discuss.elastic.co/u/warkolm)\
**Post date:** [July 13, 2015, 6:55am UTC](https://discuss.elastic.co/t/changing-mappings-of-some-group-of-ids-without-affecting-other-documents/25410/6 "2015-07-13T06:55:21Z")

</div>

That seems like a lot, you may run into issues with resources there, so you may want to refactor your doc structure.

Multi field is not being removed, check out [https://www.elastic.co/blog/great-mapping-refactoring](https://www.elastic.co/blog/great-mapping-refactoring)

---

<div class="post-metadata">

**Author:** ![apanimesh061](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/apanimesh061/32/927_2.png) [@apanimesh061](https://discuss.elastic.co/u/apanimesh061)\
**Post date:** [July 13, 2015, 6:58am UTC](https://discuss.elastic.co/t/changing-mappings-of-some-group-of-ids-without-affecting-other-documents/25410/7 "2015-07-13T06:58:33Z")

</div>

It is more like the projected no. of document sets. It might be less than that as well.

What exactly do you mean by refactoring my document structure?

---

<div class="post-metadata">

**Author:** ![warkolm](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/warkolm/32/39224_2.png) [@warkolm](https://discuss.elastic.co/u/warkolm)\
**Post date:** [July 13, 2015, 8:09am UTC](https://discuss.elastic.co/t/changing-mappings-of-some-group-of-ids-without-affecting-other-documents/25410/8 "2015-07-13T08:09:53Z")

</div>

Figure out a way to put the docs in the same index, normalise the format to remove the specific mapping or to make it applicable for multiple documents.

---

<div class="post-metadata">

**Author:** ![apanimesh061](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/apanimesh061/32/927_2.png) [@apanimesh061](https://discuss.elastic.co/u/apanimesh061)\
**Post date:** [July 13, 2015, 8:23am UTC](https://discuss.elastic.co/t/changing-mappings-of-some-group-of-ids-without-affecting-other-documents/25410/9 "2015-07-13T08:23:30Z")

</div>

Analysis has to be done on the documents belonging to one particular set. Each set can have separate analyzers associated with it. So, I don't think normalizing would be possible. Even if I create a single index, my queries will be confined to one particular document set.

---

<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, 12:01am UTC](https://discuss.elastic.co/t/changing-mappings-of-some-group-of-ids-without-affecting-other-documents/25410/10 "2017-07-06T00:01:55Z")

</div>


