# Searching with & without spaces

**URL:** <https://discuss.elastic.co/t/searching-with-without-spaces/122076>\
**Category:** Elasticsearch\
**Created:** [March 1, 2018, 1:31pm UTC](https://discuss.elastic.co/t/searching-with-without-spaces/122076 "2018-03-01T13:31:15Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![iluvcode](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/iluvcode/32/24929_2.png) [@iluvcode](https://discuss.elastic.co/u/iluvcode)\
**Post date:** [March 1, 2018, 1:31pm UTC](https://discuss.elastic.co/t/searching-with-without-spaces/122076/1 "2018-03-01T13:31:15Z")

</div>

I am using Elasticsearch 5.3 and would like to get the same results if the words have space or without space.  
example : Some of the documents have " **SM 58**" (with space) and some have " **SM58**" (without space). So when I search for "SM58"/"SM 58", I would like to get both the records. Is it possible to do this with Elasticsearch?

---

<div class="post-metadata">

**Author:** ![lars.vanderspek](https://avatars.discourse-cdn.com/v4/letter/l/e9a140/32.png) [@lars.vanderspek](https://discuss.elastic.co/u/lars.vanderspek)\
**Post date:** [March 1, 2018, 1:36pm UTC](https://discuss.elastic.co/t/searching-with-without-spaces/122076/2 "2018-03-01T13:36:41Z")

</div>

You could type "SM 58" OR "SM58" in the searchbar. The same query can be applied to a filter if you like.

---

<div class="post-metadata">

**Author:** ![iluvcode](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/iluvcode/32/24929_2.png) [@iluvcode](https://discuss.elastic.co/u/iluvcode)\
**Post date:** [March 1, 2018, 1:38pm UTC](https://discuss.elastic.co/t/searching-with-without-spaces/122076/3 "2018-03-01T13:38:48Z")

</div>

@lars.vanderspek, what filter are you referring to?

---

<div class="post-metadata">

**Author:** ![lars.vanderspek](https://avatars.discourse-cdn.com/v4/letter/l/e9a140/32.png) [@lars.vanderspek](https://discuss.elastic.co/u/lars.vanderspek)\
**Post date:** [March 1, 2018, 1:42pm UTC](https://discuss.elastic.co/t/searching-with-without-spaces/122076/4 "2018-03-01T13:42:21Z")

</div>

I made the assumption you are using Kibana. If you are, you can use a filter to query data in a certain field. If you look for your text in the \_id field, for example, it would look like this:

![image](https://us1.discourse-cdn.com/elastic/original/3X/5/6/56878133d6e43e5413004000c6d7bed643794172.png)

---

<div class="post-metadata">

**Author:** ![iluvcode](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/iluvcode/32/24929_2.png) [@iluvcode](https://discuss.elastic.co/u/iluvcode)\
**Post date:** [March 1, 2018, 1:46pm UTC](https://discuss.elastic.co/t/searching-with-without-spaces/122076/5 "2018-03-01T13:46:15Z")

</div>

I am not using Kibana. This is for a public facing website. There are multiple scenarios where we have words with/without spaces. Is there any analyzer that i can use?

---

<div class="post-metadata">

**Author:** ![lars.vanderspek](https://avatars.discourse-cdn.com/v4/letter/l/e9a140/32.png) [@lars.vanderspek](https://discuss.elastic.co/u/lars.vanderspek)\
**Post date:** [March 1, 2018, 1:56pm UTC](https://discuss.elastic.co/t/searching-with-without-spaces/122076/6 "2018-03-01T13:56:43Z")

</div>

How are you accessing your data now? Have you formulated any other queries through your current method?

---

<div class="post-metadata">

**Author:** ![iluvcode](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/iluvcode/32/24929_2.png) [@iluvcode](https://discuss.elastic.co/u/iluvcode)\
**Post date:** [March 1, 2018, 2:13pm UTC](https://discuss.elastic.co/t/searching-with-without-spaces/122076/7 "2018-03-01T14:13:04Z")

</div>

This is how i created mapping. Shortdescription & Metawords fields have words with or without spaces but the context is same. So when customer searched for SM 58 or SM58, I would like to get all the documents regardless of whitespace.  
{  
"settings": {  
"analysis": {  
"analyzer": {  
"pluralwordsAnalyzer": {  
"type": "snowball",  
"language": "English"  
},  
"htmlanalyzer": {  
"type": "custom",  
"char\_filter": ["html\_strip"],  
"tokenizer": "standard"  
},  
"trigram": {  
"type": "custom",  
"filter": ["standard", "shingle"],  
"tokenizer": "standard"  
},  
"reverse": {  
"type": "custom",  
"filter": ["standard", "reverse"],  
"tokenizer": "standard"  
}  
},  
"filter": {  
"shingle": {  
"type": "shingle",  
"min\_shingle\_size": 2,  
"max\_shingle\_size": 20  
}  
},  
"normalizer": {  
"lowercasenormalizer": {  
"type": "custom",  
"filter": ["lowercase", "asciifolding"]  
}  
}  
}  
},  
"mappings": {  
"smartsiteitemsearchentry": {  
"properties": {  
"itemId": {  
"type": "integer"  
},  
"shortDescription": {  
"type": "text",  
"fields": {  
"raw": {  
"type": "keyword",  
"normalizer": "lowercasenormalizer"  
},  
"snowball": {  
"type": "text",  
"analyzer": "pluralwordsAnalyzer",  
"search\_analyzer": "pluralwordsAnalyzer"  
}  
},  
"index": true  
},  
"itemSnapLongDesc": {  
"fields": {  
"keyword": {  
"ignore\_above": 256,  
"type": "keyword"  
}  
},  
"type": "text"  
},  
"longDescription": {  
"type": "text",  
"fields": {  
"raw": {  
"type": "keyword",  
"normalizer": "lowercasenormalizer"  
},  
"snowball": {  
"type": "text",  
"analyzer": "htmlanalyzer",  
"search\_analyzer": "pluralwordsAnalyzer"  
}  
},  
"index": true  
},  
"itemType": {  
"type": "integer"  
},  
"searchDesc": {  
"fields": {  
"keyword": {  
"ignore\_above": 256,  
"type": "keyword"  
}  
},  
"type": "text"  
},  
"keyWords": {  
"type": "text",  
"fields": {  
"raw": {  
"type": "keyword",  
"normalizer": "lowercasenormalizer"  
},  
"snowball": {  
"type": "text",  
"analyzer": "pluralwordsAnalyzer",  
"search\_analyzer": "pluralwordsAnalyzer"  
}  
},  
"index": true  
},  
"specification": {  
"type": "text",  
"fields": {  
"raw": {  
"type": "keyword",  
"normalizer": "lowercasenormalizer"  
},  
"snowball": {  
"type": "text",  
"analyzer": "htmlanalyzer",  
"search\_analyzer": "pluralwordsAnalyzer"  
}  
},  
"index": true  
},

```
				"itemGridSpecifications": {
					"properties": {
						"itemId": {
							"type": "integer"
						},
						"gridItemId": {
							"type": "integer"
						},
						"valueId": {
							"type": "integer"
						},
						"shortDescriptionSpecification": {
							"fields": {
								"keyword": {
									"ignore_above": 256,
									"type": "keyword"
								}
							},
							"type": "text"
						},
						"description": {
							"fields": {
								"keyword": {
									"ignore_above": 256,
									"type": "keyword"
								}
							},
							"type": "text"
						},
						"displayInSearchFilter": {
							"type": "boolean"
						},
						"value": {
							"fields": {
								"keyword": {
									"ignore_above": 256,
									"type": "keyword"
								}
							},
							"type": "text"
						},
						"seq": {
							"type": "integer"
						}
					},
					"type": "object"
				},
				"itemAttributes": {
					"properties": {
						"itemId": {
							"type": "integer"
						},
						"shortDescriptionAttribute": {
							"fields": {
								"keyword": {
									"ignore_above": 256,
									"type": "keyword"
								}
							},
							"type": "text"
						},
						"description": {
							"fields": {
								"keyword": {
									"ignore_above": 256,
									"type": "keyword"
								}
							},
							"type": "text"
						},
						"attributeValueId": {
							"type": "integer"
						},
						"value": {
							"fields": {
								"keyword": {
									"ignore_above": 256,
									"type": "keyword"
								}
							},
							"type": "text"
						},
						"displayInSearch": {
							"type": "boolean"
						},
						"hasRange": {
							"type": "boolean"
						},
						"sequence": {
							"type": "integer"
						}
					},
					"type": "object"
				},
			
				
				"id": {
					"type": "long"
				},
				"hasMoreRecord": {
					"type": "keyword"
				},
				"contentTypeId": {
					"type": "keyword"
				},
				"token": {
					"type": "keyword"
				},
				"itemAttributes.shortDescriptionAttribute": {
					"type": "text",
					"fields": {
						"raw": {
							"type": "keyword",
							"normalizer": "lowercasenormalizer"
						},
						"snowball": {
							"type": "text",
							"analyzer": "htmlanalyzer",
							"search_analyzer": "pluralwordsAnalyzer"
						}
					},
					"index": true
				},
				"itemGridSpecifications.shortDescriptionSpecification": {
					"type": "text",
					"fields": {
						"raw": {
							"type": "keyword",
							"normalizer": "lowercasenormalizer"
						},
						"snowball": {
							"type": "text",
							"analyzer": "htmlanalyzer",
							"search_analyzer": "pluralwordsAnalyzer"
						}
					},
					"index": true
				}
			}
		}
	}
}
```

---

<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:** [March 29, 2018, 2:13pm UTC](https://discuss.elastic.co/t/searching-with-without-spaces/122076/8 "2018-03-29T14:13:21Z")

</div>

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