# Is it normal for ES to clean up double spaces?

**URL:** <https://discuss.elastic.co/t/is-it-normal-for-es-to-clean-up-double-spaces/36675>\
**Category:** Elasticsearch\
**Created:** [December 8, 2015, 8:35pm UTC](https://discuss.elastic.co/t/is-it-normal-for-es-to-clean-up-double-spaces/36675 "2015-12-08T20:35:03Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![Donny\_Velazquez](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/donny_velazquez/32/6500_2.png) [@Donny\_Velazquez](https://discuss.elastic.co/u/Donny_Velazquez)\
**Post date:** [December 8, 2015, 8:35pm UTC](https://discuss.elastic.co/t/is-it-normal-for-es-to-clean-up-double-spaces/36675/1 "2015-12-08T20:35:03Z")

</div>

I noticed when inserting data that is a string with multiple words. ES will cleanup the spacing between them if there is more then 1 space.

Is that normal and should ES really be doing that?

---

<div class="post-metadata">

**Author:** ![polyfractal](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/polyfractal/32/48162_2.png) [@polyfractal](https://discuss.elastic.co/u/polyfractal)\
**Post date:** [December 8, 2015, 9:10pm UTC](https://discuss.elastic.co/t/is-it-normal-for-es-to-clean-up-double-spaces/36675/2 "2015-12-08T21:10:43Z")

</div>

Well, depending on what you mean, yes. 😄

By default, Elasticsearch will use the [Standard Analyzer](https://www.elastic.co/guide/en/elasticsearch/reference/2.1/analysis-standard-analyzer.html) to analyze strings. The Standard Analyzer uses a tokenizer that splits on spaces (and special characters). So if we use underscores to represent spaces, the string `"quick_brown_fox"` is tokenized into `["quick", "brown", "fox"]`.

In the case of double spaces, the tokenizer still splits on spaces...but the double space is ignored since there is no valid token found in between the spaces. E.g. `"quick__brown_fox"` (with double space after "quick") still tokenizes into `["quick", "brown", "fox"]`

Basically, ES isn't saving the spaces at all, because they are being used to tokenize. If you don't want that behavior, you can specify a new analyzer that treats spaces differently. Or set the field to `not_analyzed` and no processing will be done.

---

<div class="post-metadata">

**Author:** ![nik9000](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/nik9000/32/44947_2.png) [@nik9000](https://discuss.elastic.co/u/nik9000)\
**Post date:** [December 8, 2015, 9:29pm UTC](https://discuss.elastic.co/t/is-it-normal-for-es-to-clean-up-double-spaces/36675/3 "2015-12-08T21:29:21Z")

</div>

> [@polyfractal](#):
>
> ES isn't saving the spaces at all

Well, it is saving the `_source` and the spaces are in there. And they should be returned exactly as you sent them.

---

<div class="post-metadata">

**Author:** ![nik9000](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/nik9000/32/44947_2.png) [@nik9000](https://discuss.elastic.co/u/nik9000)\
**Post date:** [December 8, 2015, 9:29pm UTC](https://discuss.elastic.co/t/is-it-normal-for-es-to-clean-up-double-spaces/36675/4 "2015-12-08T21:29:52Z")

</div>

> [@nik9000](#):
>
> And they should be returned exactly as you sent them.

If you ask for `_source` as part of the search. Or perform a GET or something.

---

<div class="post-metadata">

**Author:** ![polyfractal](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/polyfractal/32/48162_2.png) [@polyfractal](https://discuss.elastic.co/u/polyfractal)\
**Post date:** [December 8, 2015, 9:32pm UTC](https://discuss.elastic.co/t/is-it-normal-for-es-to-clean-up-double-spaces/36675/5 "2015-12-08T21:32:12Z")

</div>

Oops yeah, that's a good point. The `_source` is always saved as-is. What I was referring to is _just_ the indexed and searchable data =)

---

<div class="post-metadata">

**Author:** ![Donny\_Velazquez](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/donny_velazquez/32/6500_2.png) [@Donny\_Velazquez](https://discuss.elastic.co/u/Donny_Velazquez)\
**Post date:** [December 8, 2015, 9:34pm UTC](https://discuss.elastic.co/t/is-it-normal-for-es-to-clean-up-double-spaces/36675/6 "2015-12-08T21:34:21Z")

</div>

I'm seeing the spaces removed in \_source also.

---

<div class="post-metadata">

**Author:** ![polyfractal](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/polyfractal/32/48162_2.png) [@polyfractal](https://discuss.elastic.co/u/polyfractal)\
**Post date:** [December 8, 2015, 9:38pm UTC](https://discuss.elastic.co/t/is-it-normal-for-es-to-clean-up-double-spaces/36675/7 "2015-12-08T21:38:06Z")

</div>

Do you have any [Source Transforms](https://www.elastic.co/guide/en/elasticsearch/reference/2.1/mapping-transform.html) enabled? Alternatively, do you perhaps have some update scripts that might strip out spaces? Or something upstream of Elasticsearch (logstash, etc) that might manipulate the string?

Source Transform and updates are the only mechanisms I can think of that actively changes the `_source` in Elasticsearch.

---

<div class="post-metadata">

**Author:** ![Donny\_Velazquez](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/donny_velazquez/32/6500_2.png) [@Donny\_Velazquez](https://discuss.elastic.co/u/Donny_Velazquez)\
**Post date:** [December 8, 2015, 9:45pm UTC](https://discuss.elastic.co/t/is-it-normal-for-es-to-clean-up-double-spaces/36675/8 "2015-12-08T21:45:19Z")

</div>

No transforms or scripts. The Address property should have extra spaces and Grantors name.

 ![](https://us1.discourse-cdn.com/elastic/original/2X/6/652fb2e7700f94f1be9d2778be89048bac0e1bbd.JPG)

---

<div class="post-metadata">

**Author:** ![nik9000](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/nik9000/32/44947_2.png) [@nik9000](https://discuss.elastic.co/u/nik9000)\
**Post date:** [December 8, 2015, 9:46pm UTC](https://discuss.elastic.co/t/is-it-normal-for-es-to-clean-up-double-spaces/36675/9 "2015-12-08T21:46:29Z")

</div>

> [@polyfractal](#):
>
> Source Transform and updates are the only mechanisms I can think of that actively changes the \_source in Elasticsearch.

Both of them turn the source into a java Map, play with the map, and then save it. It shouldn't by changing the spaces in the strings.

Honestly your best bet is posting a minimal recreation of what you are seeing with `curl`.

> [@polyfractal](#):
>
> What I was referring to is just the indexed and searchable data =)

I was really hoping you were going to tell me that I was _technically_ correct.

---

<div class="post-metadata">

**Author:** ![polyfractal](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/polyfractal/32/48162_2.png) [@polyfractal](https://discuss.elastic.co/u/polyfractal)\
**Post date:** [December 9, 2015, 4:45pm UTC](https://discuss.elastic.co/t/is-it-normal-for-es-to-clean-up-double-spaces/36675/10 "2015-12-09T16:45:01Z")

</div>

Can you execute the raw curl command and check the returned JSON? It's possible the Head plugin (which I think is what's shown in that screenshot) is munging the response for display.

How are you indexing documents? Possible something is munging the data there?

---

<div class="post-metadata">

**Author:** ![Donny\_Velazquez](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/donny_velazquez/32/6500_2.png) [@Donny\_Velazquez](https://discuss.elastic.co/u/Donny_Velazquez)\
**Post date:** [December 9, 2015, 4:59pm UTC](https://discuss.elastic.co/t/is-it-normal-for-es-to-clean-up-double-spaces/36675/11 "2015-12-09T16:59:43Z")

</div>

It's not the Head plugin because it also shows on the web app thats displaying the query result. I've looked at the json right before its being inserted into elasticsearch and it still has the extra spaces. Doing a batch insert using the C# driver [PlainElastic.Net](http://PlainElastic.Net).

Working on another project right now. So when I get a chance will post a curl example.

---

<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 5, 2017, 11:32pm UTC](https://discuss.elastic.co/t/is-it-normal-for-es-to-clean-up-double-spaces/36675/12 "2017-07-05T23:32:15Z")

</div>


