# Elasticsearch string query char to char

**URL:** <https://discuss.elastic.co/t/elasticsearch-string-query-char-to-char/258818>\
**Category:** Elasticsearch\
**Created:** [December 16, 2020, 8:19am UTC](https://discuss.elastic.co/t/elasticsearch-string-query-char-to-char/258818 "2020-12-16T08:19:04Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![adrian-arapiles](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/adrian-arapiles/32/101173_2.png) [@adrian-arapiles](https://discuss.elastic.co/u/adrian-arapiles)\
**Post date:** [December 16, 2020, 8:19am UTC](https://discuss.elastic.co/t/elasticsearch-string-query-char-to-char/258818/1 "2020-12-16T08:19:04Z")

</div>

Hi,

I need an index with phash indexed (64 length) and I have to query comparing char to char, for example:

"d1 **b** 2 **69d** 06 **e** c8158 **d** 623 **3** 3679 **a** b6693e6b **c** c **d** 43761692 **e** 6c26527dcd **d** d84c8196"

"81 **b** 0 **69d** 20 **e** 4154e **d** 7b8 **3** 71b3 **a** a4596619 **c** 6 **d** 1ee45856 **e** 8174da3cdc **d** cc6dced3"

I marked as bold the char that are equals in same position (12 in this case). I'd like to query like that and if is possible with a minimal of equals character for match as result.

I tried with **fuzzy query** but have limit of 2 interpolations as limit.  
I tried too with **span near query** but I haven't any result, maybe something wrong with mapping.

My current mapping is:

```auto
{
  "mappings": {
    "properties": {
      "phash": {
        "type": "text",
        "term_vector": "with_positions"
      }
    }
  }
}

```

And the query that I tried with **span near query** is:

```auto
{
  "query": {
      "filter": [
        {
          "span_near": {
            "clauses": [
              {
                "span_term": {
                  "phash": "d1b269d06ec8158d62333679ab6693e6bccd43761692e6c26527dcddd84c8196"
                }
              }
            ],
            "slop": 60,
            "in_order": false
          }
        }
      ]
  }
}

```

I use text and term\_vector to be able to use span queries. I had keyword before to test fuzzy query.

Any idea or suggest?

Thanks in advance,  
Adrian.

---

<div class="post-metadata">

**Author:** ![adrian-arapiles](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/adrian-arapiles/32/101173_2.png) [@adrian-arapiles](https://discuss.elastic.co/u/adrian-arapiles)\
**Post date:** [January 11, 2021, 8:29am UTC](https://discuss.elastic.co/t/elasticsearch-string-query-char-to-char/258818/2 "2021-01-11T08:29:43Z")

</div>

Hi,  
Any idea about that?

Thanks,  
Adrian.

---

<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:** [January 11, 2021, 9:29am UTC](https://discuss.elastic.co/t/elasticsearch-string-query-char-to-char/258818/3 "2021-01-11T09:29:39Z")

</div>

> [@adrian-arapiles](#):
>
> d1 **b** 2 **69d** 06 **e** c8158 **d** 623 **3** 3679 **a** b6693e6b **c** c **d** 43761692 **e** 6c26527dcd **d** d84c8196

64 fields - one for each char would be manageable.  
64 query clauses of the type `c1:d OR c2:1 OR c3:b OR c4:2` would also be manageable.

---

<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:** [February 8, 2021, 9:29am UTC](https://discuss.elastic.co/t/elasticsearch-string-query-char-to-char/258818/4 "2021-02-08T09:29:52Z")

</div>

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