# How to add "position\_increment\_gap" in a field created by a Crawler Index?

**URL:** <https://discuss.elastic.co/t/how-to-add-position-increment-gap-in-a-field-created-by-a-crawler-index/357170>\
**Category:** Elastic Search\
**Tags:** elastic-app-search\
**Created:** [April 10, 2024, 9:43pm UTC](https://discuss.elastic.co/t/how-to-add-position-increment-gap-in-a-field-created-by-a-crawler-index/357170 "2024-04-10T21:43:07Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![freddyrb](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/freddyrb/32/133428_2.png) [@freddyrb](https://discuss.elastic.co/u/freddyrb)\
**Post date:** [April 10, 2024, 9:43pm UTC](https://discuss.elastic.co/t/how-to-add-position-increment-gap-in-a-field-created-by-a-crawler-index/357170/1 "2024-04-10T21:43:08Z")

</div>

I have a index created by a crawler and it creates a Title field, but when I'm trying to do a match\_phrase\_prefix search I have the error `"failed to create query: field:[title] was indexed without position data; cannot run PhraseQuery"` I read that it needs to be added the "position\_increment\_gap", but when I tried to add it in the mappings, there's no way, gets me the error :

```auto
"type": "resource_already_exists_exception",
        "reason": "index [search-index1/BCnmIxvbQD-SUdKfU_IRpg] already exists".

```

My question is, how to add that attribute to the mapping if it's created by a crawler index?

I need to do a match\_phrase\_prefix to check exact matches on the title. It works for "match" only.

---

<div class="post-metadata">

**Author:** ![Jedr\_Blaszyk](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jedr_blaszyk/32/127637_2.png) [@Jedr\_Blaszyk](https://discuss.elastic.co/u/Jedr_Blaszyk)\
**Post date:** [April 16, 2024, 12:08pm UTC](https://discuss.elastic.co/t/how-to-add-position-increment-gap-in-a-field-created-by-a-crawler-index/357170/2 "2024-04-16T12:08:46Z")

</div>

Hi @freddyrb. The default mapping of the `title` field in a crawler index should support `match_phrase_prefix` queries. Can you try running a simple query and see if it works?

```auto
GET search-test/_search
{
  "query": {
    "match_phrase_prefix": {
      "title": <your query>
    }
  },
  "_source": ["title"]
} 

```

The [position\_increment\_gap](https://www.elastic.co/guide/en/elasticsearch/reference/current/position-increment-gap.html) seems to be only used for multi-valued fields .

If this doesn't help, can you share your search query so that we can help with troubleshooting?

---

<div class="post-metadata">

**Author:** ![freddyrb](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/freddyrb/32/133428_2.png) [@freddyrb](https://discuss.elastic.co/u/freddyrb)\
**Post date:** [April 16, 2024, 7:37pm UTC](https://discuss.elastic.co/t/how-to-add-position-increment-gap-in-a-field-created-by-a-crawler-index/357170/3 "2024-04-16T19:37:35Z")

</div>

Thanks @Jedr_Blaszyk , thanks for the answer. The query is:

```auto
GET search-testindex1/_search
{
  "query": {
    "match_phrase_prefix": {
      "title": "nuxeo drive"
    }
  },
  "_source": ["title"]
}

```

The problem is when I send more than one word, I want to search the documents that has in the title the "nuxeo drive" phrase, I don't want that Elastic search "nuxeo" and "drive" separated. Then I get the error.

 ![image](https://us1.discourse-cdn.com/elastic/original/3X/a/4/a40c55e69970aeca333641b906c5e63f3e490d73.png)

The part of the query:

```auto
"query": {
    "bool": {
      "filter": {
        "terms": {
          "indexedContentType.keyword": [
            "Documents,TSKB Article,blog,forum"
          ]
        }
      },
      "must": {
        "bool": {
          "should": [
            {
              "match_phrase_prefix": {
                "title": {
                  "query": "Documentation Docs Home Getting Starte"
                }
              }
            },
            {
              "match_phrase_prefix": {
                "subject": {
                  "query": "Documentation Docs Home Getting Starte"
                }
              }
            },

```

---

<div class="post-metadata">

**Author:** ![Jedr\_Blaszyk](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jedr_blaszyk/32/127637_2.png) [@Jedr\_Blaszyk](https://discuss.elastic.co/u/Jedr_Blaszyk)\
**Post date:** [April 17, 2024, 10:01am UTC](https://discuss.elastic.co/t/how-to-add-position-increment-gap-in-a-field-created-by-a-crawler-index/357170/4 "2024-04-17T10:01:07Z")

</div>

Aha! Now, looking at the example you provided I understand the issue. Your default template mapping of `search-testindex1` should already include a number of subfields for `title` property, that are indexed differently, to be suitable for a range of queries.

The `stem` subfield of `title` is indexed with position information. You can try running:

```auto
GET search-testindex1/_search
{
  "query": {
    "match_phrase_prefix": {
      "title.stem": "nuxeo drive"
    }
  },
  "_source": ["title"]
}

```

Let me know if it helps!

Also, you can always extend your existing mapping with a subfield or a new field. Here is an example of how to add a subfield called `phrase` to `title` property:

```auto
PUT search-testindex1/_mapping
{
  "properties": {
    "title": {
      "type": "text",
      "fields": {
        "phrase": {
          "type": "text",
          "index_options": "positions",
          "analyzer": "iq_text_base"
        }
      },
      "index_options": "freqs",
      "analyzer": "iq_text_base"
    }
  }
}

```

---

<div class="post-metadata">

**Author:** ![freddyrb](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/freddyrb/32/133428_2.png) [@freddyrb](https://discuss.elastic.co/u/freddyrb)\
**Post date:** [April 17, 2024, 3:44pm UTC](https://discuss.elastic.co/t/how-to-add-position-increment-gap-in-a-field-created-by-a-crawler-index/357170/5 "2024-04-17T15:44:30Z")

</div>

Thanks @Jedr_Blaszyk , I will see your suggestions, but my use case is a query with multiple indexes that have the field Title, and in all of them I have results (API Type) except in the Crawler index that throws the error.

Any suggestion?

---

<div class="post-metadata">

**Author:** ![Jedr\_Blaszyk](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jedr_blaszyk/32/127637_2.png) [@Jedr\_Blaszyk](https://discuss.elastic.co/u/Jedr_Blaszyk)\
**Post date:** [April 18, 2024, 2:03pm UTC](https://discuss.elastic.co/t/how-to-add-position-increment-gap-in-a-field-created-by-a-crawler-index/357170/6 "2024-04-18T14:03:17Z")

</div>

> my use case is a query with multiple indexes that have the field `title`

Ok, that complicates things a bit but I see 2 ways forward to support your use case.

**Solution 1** : index filter inside a bool query: more manageable, with slight query-time performance hit

Example query:

```auto
GET index1,index2,index3,crawler_index/_search
{
  "query": {
    "bool": {
      "should": [
        {
          "bool": {
            "must": {
              "multi_match": {
                "query": {query},
                "type": "phrase_prefix",
                "fields": ["title"]
              }
            },
            "must_not": {
              "terms": {
                "_index": ["crawler_index"]
              }
            }
          }
        },
        {
          "bool": {
            "must": {
              "multi_match": {
                "query": {query},
                "type": "phrase_prefix",
                "fields": ["title.stem"]
              }
            },
            "filter": {
              "terms": {
                "_index": ["crawler_index"]
              }
            }
          }
        }
      ],
      "minimum_should_match": 1
    }
  }
}

```

**Solution 2:** Update mappings in other indices with same subfield e.g. `title.stem` (indexed with position data) and reindex the data. A bit more work for you, but resulting slightly better query time performance. In that way you would be able to run query like:

```auto
GET index1,index2,index3,crawler_index/_search
{
  "query": {
    "match_phrase_prefix": {
      "title.stem": {query}
    }
  }
}

```

Hope this helps!

---

<div class="post-metadata">

**Author:** ![freddyrb](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/freddyrb/32/133428_2.png) [@freddyrb](https://discuss.elastic.co/u/freddyrb)\
**Post date:** [April 18, 2024, 5:04pm UTC](https://discuss.elastic.co/t/how-to-add-position-increment-gap-in-a-field-created-by-a-crawler-index/357170/7 "2024-04-18T17:04:07Z")

</div>

Thanks, I will check those options.

---

<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:** [May 16, 2024, 5:04pm UTC](https://discuss.elastic.co/t/how-to-add-position-increment-gap-in-a-field-created-by-a-crawler-index/357170/8 "2024-05-16T17:04:49Z")

</div>

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