# Search with whitespace again

**URL:** <https://discuss.elastic.co/t/search-with-whitespace-again/7031>\
**Category:** Elasticsearch\
**Created:** [March 16, 2012, 4:43pm UTC](https://discuss.elastic.co/t/search-with-whitespace-again/7031 "2012-03-16T16:43:21Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Alexander\_Sviridov](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/alexander_sviridov/32/31375_2.png) [@Alexander\_Sviridov](https://discuss.elastic.co/u/Alexander_Sviridov)\
**Post date:** [March 16, 2012, 4:43pm UTC](https://discuss.elastic.co/t/search-with-whitespace-again/7031/1 "2012-03-16T16:43:21Z")

</div>

Hello!  
I've run into same problem as described in this post:  
[http://elasticsearch-users.115913.n3.nabble.com/Search-with-white-space-td2574112.html](http://elasticsearch-users.115913.n3.nabble.com/Search-with-white-space-td2574112.html)

Query just doesn't return anything if there are more than one search  
term — query "Centre" returns document, containing "Centre Est",  
"Centre E" returns nothing.

Tried to use the "shingle" token filter and the "nGram" tokenizer  
(separately) — no luck ☹

here is the config:

index :  
analysis :  
analyzer :  
myAnalyzer2 :  
type : custom  
tokenizer : standard  
filter : [shingle]

mapping:  
"street" : {  
"type" : "multi\_field",  
"fields" : {  
"street\_untouched" : {  
"include\_in\_all" : false,  
"index" : "not\_analyzed",  
"type" : "string"  
},  
"street\_shingles" : {  
"include\_in\_all" : false,  
"analyzer" : "myAnalyzer2",  
"type" : "string"  
},  
"street" : {  
"type" : "string"  
}  
}  
},

And this is query:

{"size"=\>20,  
"query"=\>  
{"bool"=\>  
{"should"=\>  
[{"prefix"=\>{"street"=\>"some str"}},  
{"prefix"=\>{"street\_shingles"=\>"some str"}},  
{"prefix"=\>{"street\_untouched"=\>"some str"}}]}}}

I would appreciate any corrections, advices or debug tips (is there a  
way to peek inside the index?).  
Thank you!

---

<div class="post-metadata">

**Author:** ![kimchy](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kimchy/32/44952_2.png) [@kimchy](https://discuss.elastic.co/u/kimchy)\
**Post date:** [March 17, 2012, 10:36am UTC](https://discuss.elastic.co/t/search-with-whitespace-again/7031/2 "2012-03-17T10:36:56Z")

</div>

The prefix query / filter do not perform analysis on the searched text, so  
its basically expects a "full" match on it. For example, "hello world" when  
indexed, is broken down into "hello" and "world" (with the standard  
analyzer). Doing a prefix query on "hell" will work well (because hello  
starts with hell), but doing a prefix query for "hello wo" will not work,  
because there is no term that starts with "hello wo" (we have "hello" and  
"world").

What you can do is use the text query, with the text\_phrase\_prefix option (  
[Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/query-dsl/text-query.html)),  
which builds a complex query that tries to act as a proper _analyzed_  
prefix query. Note though, when using ngram, you usually don't really need  
a prefix query..., ngram already "does" it for you at indexing time.

On Fri, Mar 16, 2012 at 6:43 PM, Alexander Sviridov \<  
[alexander.sviridov@gmail.com](mailto:alexander.sviridov@gmail.com)\> wrote:

> Hello!  
> I've run into same problem as described in this post:
> 
> [http://elasticsearch-users.115913.n3.nabble.com/Search-with-white-space-td2574112.html](http://elasticsearch-users.115913.n3.nabble.com/Search-with-white-space-td2574112.html)
> 
> Query just doesn't return anything if there are more than one search  
> term — query "Centre" returns document, containing "Centre Est",  
> "Centre E" returns nothing.
> 
> Tried to use the "shingle" token filter and the "nGram" tokenizer  
> (separately) — no luck ☹
> 
> here is the config:
> 
> index :  
> analysis :  
> analyzer :  
> myAnalyzer2 :  
> type : custom  
> tokenizer : standard  
> filter : [shingle]
> 
> mapping:  
> "street" : {  
> "type" : "multi\_field",  
> "fields" : {  
> "street\_untouched" : {  
> "include\_in\_all" : false,  
> "index" : "not\_analyzed",  
> "type" : "string"  
> },  
> "street\_shingles" : {  
> "include\_in\_all" : false,  
> "analyzer" : "myAnalyzer2",  
> "type" : "string"  
> },  
> "street" : {  
> "type" : "string"  
> }  
> }  
> },
> 
> And this is query:
> 
> {"size"=\>20,  
> "query"=\>  
> {"bool"=\>  
> {"should"=\>  
> [{"prefix"=\>{"street"=\>"some str"}},  
> {"prefix"=\>{"street\_shingles"=\>"some str"}},  
> {"prefix"=\>{"street\_untouched"=\>"some str"}}]}}}
> 
> I would appreciate any corrections, advices or debug tips (is there a  
> way to peek inside the index?).  
> Thank you!

---

<div class="post-metadata">

**Author:** ![Alexander\_Sviridov](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/alexander_sviridov/32/31375_2.png) [@Alexander\_Sviridov](https://discuss.elastic.co/u/Alexander_Sviridov)\
**Post date:** [March 17, 2012, 3:43pm UTC](https://discuss.elastic.co/t/search-with-whitespace-again/7031/3 "2012-03-17T15:43:03Z")

</div>

Oh, it's exaclty what I was looking for, and there is no need for  
multi fields and custom analyzers, as far as I see.

Thank you very much!

On Mar 17, 2:36 pm, Shay Banon [kim...@gmail.com](mailto:kim...@gmail.com) wrote:

> The prefix query / filter do not perform analysis on the searched text, so  
> its basically expects a "full" match on it. For example, "hello world" when  
> indexed, is broken down into "hello" and "world" (with the standard  
> analyzer). Doing a prefix query on "hell" will work well (because hello  
> starts with hell), but doing a prefix query for "hello wo" will not work,  
> because there is no term that starts with "hello wo" (we have "hello" and  
> "world").
> 
> What you can do is use the text query, with the text\_phrase\_prefix option ([Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/query-dsl/text-query.html)),  
> which builds a complex query that tries to act as a proper _analyzed_  
> prefix query. Note though, when using ngram, you usually don't really need  
> a prefix query..., ngram already "does" it for you at indexing time.
> 
> On Fri, Mar 16, 2012 at 6:43 PM, Alexander Sviridov \<
> 
> [alexander.sviri...@gmail.com](mailto:alexander.sviri...@gmail.com)\> wrote:
> 
> > Hello!  
> > I've run into same problem as described in this post:
> 
> > [http://elasticsearch-users.115913.n3.nabble.com/Search-with-white-spa](http://elasticsearch-users.115913.n3.nabble.com/Search-with-white-spa)...
> 
> > Query just doesn't return anything if there are more than one search  
> > term — query "Centre" returns document, containing "Centre Est",  
> > "Centre E" returns nothing.
> 
> > Tried to use the "shingle" token filter and the "nGram" tokenizer  
> > (separately) — no luck ☹
> 
> > here is the config:
> 
> > index :  
> > analysis :  
> > analyzer :  
> > myAnalyzer2 :  
> > type : custom  
> > tokenizer : standard  
> > filter : [shingle]
> 
> > mapping:  
> > "street" : {  
> > "type" : "multi\_field",  
> > "fields" : {  
> > "street\_untouched" : {  
> > "include\_in\_all" : false,  
> > "index" : "not\_analyzed",  
> > "type" : "string"  
> > },  
> > "street\_shingles" : {  
> > "include\_in\_all" : false,  
> > "analyzer" : "myAnalyzer2",  
> > "type" : "string"  
> > },  
> > "street" : {  
> > "type" : "string"  
> > }  
> > }  
> > },
> 
> > And this is query:
> 
> > {"size"=\>20,  
> > "query"=\>  
> > {"bool"=\>  
> > {"should"=\>  
> > [{"prefix"=\>{"street"=\>"some str"}},  
> > {"prefix"=\>{"street\_shingles"=\>"some str"}},  
> > {"prefix"=\>{"street\_untouched"=\>"some str"}}]}}}
> 
> > I would appreciate any corrections, advices or debug tips (is there a  
> > way to peek inside the index?).  
> > Thank you!

---

<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 6, 2017, 3:35am UTC](https://discuss.elastic.co/t/search-with-whitespace-again/7031/4 "2017-07-06T03:35:44Z")

</div>


