# Contains query on text field with keyword analyzer breaking at whitespace

**URL:** <https://discuss.elastic.co/t/contains-query-on-text-field-with-keyword-analyzer-breaking-at-whitespace/126866>\
**Category:** Elasticsearch\
**Created:** [April 5, 2018, 7:40am UTC](https://discuss.elastic.co/t/contains-query-on-text-field-with-keyword-analyzer-breaking-at-whitespace/126866 "2018-04-05T07:40:34Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![nmathur](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/nmathur/32/21451_2.png) [@nmathur](https://discuss.elastic.co/u/nmathur)\
**Post date:** [April 5, 2018, 7:40am UTC](https://discuss.elastic.co/t/contains-query-on-text-field-with-keyword-analyzer-breaking-at-whitespace/126866/1 "2018-04-05T07:40:34Z")

</div>

Hello,

I need to perform in query on the field with "keyword" analyzer.

An exact search is successful and return correct result but contains query always fail. I also needed the keyword to search with lower case so I tried [this](https://stackoverflow.com/questions/46108872/elasticsearch-5-case-insensitive-exact-matching-in-a-text-keyword-field) and it is working .. here is the code

```
        'var descriptor = new CreateIndexDescriptor("myindex")
               .Settings(s => s
                    .Analysis(a => a
                        .Analyzers(an => an
                            .Custom("case_insensitive", ca => ca
                                .Tokenizer("keyword")
                                .Filters("lowercase")
                            )
                        )
                    ))
            .Mappings(ms => ms
                             .Map<Employee>("employee", m => m.AutoMap().Properties(p => p
                                  .Text(t => t.Name(n => n.Name).Analyzer("case_insensitive").Fielddata(true))                                      
                              )));
        var response = ESContext.CreateIndex(descriptor);'

```

Above created this mapping

> "name": {  
> "type": "text",  
> "analyzer": "case\_insensitive",  
> "fielddata": true  
> },

Now when I have these names =\>  
**1. Namrata Mathur**  
**2. Namrata**  
**3. Namrata Rai**

If I apply contains search and look for "Namrata Mathur" I am only getting 2nd row "Namrata" .. and when I type a whitespace I am getting all three rows.

Here it the query which [ElasticLinq](https://github.com/ElasticLINQ/ElasticLINQ/tree/elasticsearch5) generating:  
{

> "query":{"bool":{"must":[{"term":{"archive":false}},{"query\_string":{"query":"Namrata Mathur\*","fields":["name"]}},{"term":{"companyId":4}}]}},"size":100,"timeout":"10s"}

Please help me, what should I do now .. why my search breaks at whitespace .. please guide.

---

<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:** [May 3, 2018, 7:40am UTC](https://discuss.elastic.co/t/contains-query-on-text-field-with-keyword-analyzer-breaking-at-whitespace/126866/2 "2018-05-03T07:40:46Z")

</div>

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