# Index prefixes on fields

**URL:** https://discuss.elastic.co/t/index-prefixes-on-fields/202165
**Category:** Elasticsearch
**Created:** [October 3, 2019, 12:31pm UTC](https://discuss.elastic.co/t/index-prefixes-on-fields/202165 "2019-10-03T12:31:09Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![Sune\_Debel](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/sune_debel/32/48265_2.png) [@Sune\_Debel](https://discuss.elastic.co/u/Sune_Debel)
#### Post date: [October 3, 2019, 12:31pm UTC](https://discuss.elastic.co/t/index-prefixes-on-fields/202165/1 "2019-10-03T12:31:09Z")

</div>

We have a setup where some fields are analyzed in multiple ways: with the `standard` analyzer and a custom analyzer `my_analyzer` that preserves punctuation and capitalisation. We want to be able to perform prefix search on both fields. As such we want to apply `index_prefixes` to the relevant fields. We have tried the following mapping

```javascript
{
  "mapping": {
    "properties": {
      "field1": {
        "type": "text",
        "index_prefixes": {},
        "fields": {
          "exact": {
            "type": "text"
            "analyzer": "my_analyzer",
            "index_prefixes": {}
          }
        }
      },
      "field2": {
        "type": "text",
        "index_prefixes": {},
        "fields": {
          "exact": {
            "type": "text"
            "analyzer": "my_analyzer",
            "index_prefixes": {}
          }
        }
      }
    }
  }
}

```

But creating an index with this mapping produces:

```javascript
{
    "error": {
        "root_cause": [
            {
                "type": "illegal_argument_exception",
                "reason": "Field [exact._index_prefix] is defined twice."
            }
        ],
        "type": "illegal_argument_exception",
        "reason": "Field [exact._index_prefix] is defined twice."
    },
    "status": 400
}

```

If we remove the `index_prefixes` from the `exact` fields, the index creation succeeds. In other words, change the mapping to:

```javascript
{
  "mapping": {
    "properties": {
      "field1": {
        "type": "text",
        "index_prefixes": {},
        "fields": {
          "exact": {
            "type": "text"
            "analyzer": "my_analyzer"
          }
        }
      },
      "field2": {
        "type": "text",
        "index_prefixes": {},
        "fields": {
          "exact": {
            "type": "text"
            "analyzer": "my_analyzer"
          }
        }
      }
    }
  }
}

```

But are prefixes indexed on `field1.exact` and `field2.exact` if `index_prefixes` is only present on the `field1` and `field2`? If not, what is the correct way to do this? The documentation does not mention anything about fields.

---

<div class="post-metadata">

### Author: ![AlanWoodward](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/alanwoodward/32/41962_2.png) [@AlanWoodward](https://discuss.elastic.co/u/AlanWoodward)
#### Post date: [October 11, 2019, 9:17am UTC](https://discuss.elastic.co/t/index-prefixes-on-fields/202165/2 "2019-10-11T09:17:34Z")

</div>

Hi, this is a known bug that was fixed in the 7.2.1 release: [https://github.com/elastic/elasticsearch/pull/43862](https://github.com/elastic/elasticsearch/pull/43862)

-Alan

---

<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: [November 8, 2019, 9:31am UTC](https://discuss.elastic.co/t/index-prefixes-on-fields/202165/3 "2019-11-08T09:31:30Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
