# Search for documents containing words with and without dots (e.g. “ceo”, “c.e.o”, “c.e.o.”)

**URL:** https://discuss.elastic.co/t/search-for-documents-containing-words-with-and-without-dots-e-g-ceo-c-e-o-c-e-o/319035
**Category:** Elasticsearch
**Created:** [November 16, 2022, 8:54am UTC](https://discuss.elastic.co/t/search-for-documents-containing-words-with-and-without-dots-e-g-ceo-c-e-o-c-e-o/319035 "2022-11-16T08:54:08Z")
**Posts on this page:** 13
**Page:** 1

<div class="post-metadata">

### Author: ![revencu](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/revencu/32/113404_2.png) [@revencu](https://discuss.elastic.co/u/revencu)
#### Post date: [November 16, 2022, 8:54am UTC](https://discuss.elastic.co/t/search-for-documents-containing-words-with-and-without-dots-e-g-ceo-c-e-o-c-e-o/319035/1 "2022-11-16T08:54:08Z")

</div>

```auto
{
   "query":{
      "match":{
         "title": "ceo"
      }
   }
}

```

this query returns docs that only contain "ceo", "Ceo", "CEO". But the index has values like "c.e.o.", "C.E.O.", "c.e.o"  
How to set up a query so that when searching for "ceo" it also returns docs with values that contain dots?

---

<div class="post-metadata">

### Author: ![RabBit\_BR](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rabbit_br/32/82261_2.png) [@RabBit\_BR](https://discuss.elastic.co/u/RabBit_BR)
#### Post date: [November 16, 2022, 9:03am UTC](https://discuss.elastic.co/t/search-for-documents-containing-words-with-and-without-dots-e-g-ceo-c-e-o-c-e-o/319035/2 "2022-11-16T09:03:48Z")

</div>

Hi @revencu

You have some options to resolve that.

I believe you can use synonyms. This [article](https://www.elastic.co/blog/boosting-the-power-of-elasticsearch-with-synonyms) is a good introduction.

Another option is create a custom analyzer to replace ".".

```auto
GET _analyze
{
  "tokenizer": "standard",
  "filter": [
    {
      "type": "pattern_replace",
      "pattern": "\\.",
      "replacement": ""
    }
  ],
  "text": "c.e.o"
}

```

Tokens

```auto
{
  "tokens": [
    {
      "token": "ceo",
      "start_offset": 0,
      "end_offset": 5,
      "type": "<ALPHANUM>",
      "position": 0
    }
  ]
}

```

---

<div class="post-metadata">

### Author: ![revencu](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/revencu/32/113404_2.png) [@revencu](https://discuss.elastic.co/u/revencu)
#### Post date: [November 16, 2022, 9:06am UTC](https://discuss.elastic.co/t/search-for-documents-containing-words-with-and-without-dots-e-g-ceo-c-e-o-c-e-o/319035/3 "2022-11-16T09:06:06Z")

</div>

I created analyzer but it not help

```auto
{
    "analysis": {
      "analyzer": {
        "remove_dots": {
          "tokenizer": "standard",
          "type": "custom",
          "char_filter": ["my_char_filter"]
        }
      },
      "char_filter": {
        "my_char_filter": {"type": "pattern_replace", "pattern":"[.]+", "replacement":""}
      },
     "filter": ["lowercase", "asciifolding"],
    }
  }

```

---

<div class="post-metadata">

### Author: ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)
#### Post date: [November 16, 2022, 9:19am UTC](https://discuss.elastic.co/t/search-for-documents-containing-words-with-and-without-dots-e-g-ceo-c-e-o-c-e-o/319035/4 "2022-11-16T09:19:13Z")

</div>

Could you provide a full recreation script as described in [About the Elasticsearch category](https://discuss.elastic.co/t/about-the-elasticsearch-category/21). It will help to better understand what you are doing. Please, try to keep the example as simple as possible.

A full reproduction script is something anyone can **copy and paste in Kibana dev console** , click on the run button to reproduce your use case. It will help readers to understand, reproduce and if needed fix your problem. It will also most likely help to get a faster answer.

---

<div class="post-metadata">

### Author: ![RabBit\_BR](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rabbit_br/32/82261_2.png) [@RabBit\_BR](https://discuss.elastic.co/u/RabBit_BR)
#### Post date: [November 16, 2022, 9:21am UTC](https://discuss.elastic.co/t/search-for-documents-containing-words-with-and-without-dots-e-g-ceo-c-e-o-c-e-o/319035/5 "2022-11-16T09:21:19Z")

</div>

I think this filter is misplaced.

Look my example that return all documents when search "ceo".

```auto
PUT my-index-000001
{
  "settings": {
    "analysis": {
      "analyzer": {
        "remove_dots": {
          "tokenizer": "standard",
          "type": "custom",
          "char_filter": [
            "my_char_filter"
          ],
          "filter": [
            "lowercase",
            "asciifolding"
          ]
        }
      },
      "char_filter": {
        "my_char_filter": {
          "type": "pattern_replace",
          "pattern": "[.]+",
          "replacement": ""
        }
      }
    }
  },
  "mappings": {
    "properties": {
      "description": {
        "type": "text",
        "analyzer": "remove_dots"
      }
    }
  }
}

POST my-index-000001/_bulk
{"index":{}}
{"description":"someone is C.E.O"}
{"index":{}}
{"description":"someone is c.e.o"}
{"index":{}}
{"description":"someone is c.e.o."}
{"index":{}}
{"description":"someone is ceo"}

POST my-index-000001/_search 
{
  "query": {
    "match": {
      "description": "ceo"
    }
  }
}

```

---

<div class="post-metadata">

### Author: ![revencu](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/revencu/32/113404_2.png) [@revencu](https://discuss.elastic.co/u/revencu)
#### Post date: [November 16, 2022, 9:31am UTC](https://discuss.elastic.co/t/search-for-documents-containing-words-with-and-without-dots-e-g-ceo-c-e-o-c-e-o/319035/6 "2022-11-16T09:31:10Z")

</div>

I can't make a mapping because I have a huge index

```auto
 "mappings": {
    "properties": {
      "description": {
        "type": "text",
        "analyzer": "remove_dots"
      }
    }
  }

```

So, I use this request but it not return values with dots

```auto
                    {
                         "match":{
                              "title": {
                                   "query":'ceo',
                                   "analyzer": "remove_dots"
                              }
                         },
                    },

```

---

<div class="post-metadata">

### Author: ![RabBit\_BR](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rabbit_br/32/82261_2.png) [@RabBit\_BR](https://discuss.elastic.co/u/RabBit_BR)
#### Post date: [November 16, 2022, 9:47am UTC](https://discuss.elastic.co/t/search-for-documents-containing-words-with-and-without-dots-e-g-ceo-c-e-o-c-e-o/319035/7 "2022-11-16T09:47:06Z")

</div>

OK. In that case I think you have to think otherwise.  
Your document token looks something like this: "ceo", "Ceo", "CEO", "c.e.o.", "C.E.O.", "c.e.o".  
As you cannot apply an analyzer at indexing time you have to add it at search time.  
It would be better for you to add having the analyzer to "." in the search terms so you can get the match in "c.e.o.", "C.E.O.", "c.e.o".

Your query would have to be a should clausule because you will use the match for the term "ceo" and another match for the term "ceo" but with the analyzer that adds the ".".

---

<div class="post-metadata">

### Author: ![revencu](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/revencu/32/113404_2.png) [@revencu](https://discuss.elastic.co/u/revencu)
#### Post date: [November 16, 2022, 9:56am UTC](https://discuss.elastic.co/t/search-for-documents-containing-words-with-and-without-dots-e-g-ceo-c-e-o-c-e-o/319035/8 "2022-11-16T09:56:21Z")

</div>

Is any way to find in field that before removing all dots without script query?

---

<div class="post-metadata">

### Author: ![RabBit\_BR](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rabbit_br/32/82261_2.png) [@RabBit\_BR](https://discuss.elastic.co/u/RabBit_BR)
#### Post date: [November 16, 2022, 10:26am UTC](https://discuss.elastic.co/t/search-for-documents-containing-words-with-and-without-dots-e-g-ceo-c-e-o-c-e-o/319035/9 "2022-11-16T10:26:03Z")

</div>

By the scenario I don't know any other solution besides the ones presented, but maybe someone knows something new.

---

<div class="post-metadata">

### Author: ![revencu](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/revencu/32/113404_2.png) [@revencu](https://discuss.elastic.co/u/revencu)
#### Post date: [November 16, 2022, 10:28am UTC](https://discuss.elastic.co/t/search-for-documents-containing-words-with-and-without-dots-e-g-ceo-c-e-o-c-e-o/319035/10 "2022-11-16T10:28:52Z")

</div>

Thank you, but this solution not work on my side

---

<div class="post-metadata">

### Author: ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)
#### Post date: [November 16, 2022, 11:31am UTC](https://discuss.elastic.co/t/search-for-documents-containing-words-with-and-without-dots-e-g-ceo-c-e-o-c-e-o/319035/11 "2022-11-16T11:31:22Z")

</div>

The best option is to reindex your dataset. You can look at the reindex API for this.

---

<div class="post-metadata">

### Author: ![revencu](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/revencu/32/113404_2.png) [@revencu](https://discuss.elastic.co/u/revencu)
#### Post date: [November 16, 2022, 11:43am UTC](https://discuss.elastic.co/t/search-for-documents-containing-words-with-and-without-dots-e-g-ceo-c-e-o-c-e-o/319035/12 "2022-11-16T11:43:04Z")

</div>

Yes, make sense, but I cannot do this for a huge index (700M records).

---

<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: [December 14, 2022, 11:43am UTC](https://discuss.elastic.co/t/search-for-documents-containing-words-with-and-without-dots-e-g-ceo-c-e-o-c-e-o/319035/13 "2022-12-14T11:43:22Z")

</div>

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