# Searching term with it's position range

**URL:** <https://discuss.elastic.co/t/searching-term-with-its-position-range/236984>\
**Category:** Elasticsearch\
**Created:** [June 13, 2020, 3:36pm UTC](https://discuss.elastic.co/t/searching-term-with-its-position-range/236984 "2020-06-13T15:36:08Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Kazuki\_Matsuda](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kazuki_matsuda/32/70303_2.png) [@Kazuki\_Matsuda](https://discuss.elastic.co/u/Kazuki_Matsuda)\
**Post date:** [June 13, 2020, 3:36pm UTC](https://discuss.elastic.co/t/searching-term-with-its-position-range/236984/1 "2020-06-13T15:36:08Z")

</div>

Hello, I have a following three document

```
1. `{field: "one two three"}`
2. `{field: "x one two three"}`
3. `{field: "x y one two three"}`

```

Question: Can I query term `tow` with it's position range?  
Example: `{match: "two", position: [4, 6]}` returns 1 & 2 because term "two" position 4 and 6.  
#3 is not returned because position of "two" is 8

---

<div class="post-metadata">

**Author:** ![Vinayak\_Sapre](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/vinayak_sapre/32/45939_2.png) [@Vinayak\_Sapre](https://discuss.elastic.co/u/Vinayak_Sapre)\
**Post date:** [June 14, 2020, 4:21pm UTC](https://discuss.elastic.co/t/searching-term-with-its-position-range/236984/2 "2020-06-14T16:21:13Z")

</div>

You can use regex query

```auto
{
  "query": {
    "regexp": {
      "field.keyword": {
        "value": ".{4}.?{2}two.*"
      }
    }
  }
}

```

---

<div class="post-metadata">

**Author:** ![Kazuki\_Matsuda](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kazuki_matsuda/32/70303_2.png) [@Kazuki\_Matsuda](https://discuss.elastic.co/u/Kazuki_Matsuda)\
**Post date:** [June 15, 2020, 3:30pm UTC](https://discuss.elastic.co/t/searching-term-with-its-position-range/236984/3 "2020-06-15T15:30:53Z")

</div>

Thank you for your response.  
But looks like this performance is not good because I can't use index.

Is it possible using index for this case?

---

<div class="post-metadata">

**Author:** ![Mark\_Harwood](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mark_harwood/32/10538_2.png) [@Mark\_Harwood](https://discuss.elastic.co/u/Mark_Harwood)\
**Post date:** [June 16, 2020, 9:26am UTC](https://discuss.elastic.co/t/searching-term-with-its-position-range/236984/4 "2020-06-16T09:26:44Z")

</div>

> [@Kazuki\_Matsuda](#):
>
> Is it possible using index for this case?

In 7.9 we will be introducing [a new field type](https://www.elastic.co/guide/en/elasticsearch/reference/7.x/wildcard.html) that index-accelerates regex and wildcard searches like this.

---

<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 14, 2020, 9:26am UTC](https://discuss.elastic.co/t/searching-term-with-its-position-range/236984/5 "2020-07-14T09:26:55Z")

</div>

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