# Query with Text field

**URL:** <https://discuss.elastic.co/t/query-with-text-field/334687>\
**Category:** Elasticsearch\
**Created:** [May 30, 2023, 1:33pm UTC](https://discuss.elastic.co/t/query-with-text-field/334687 "2023-05-30T13:33:42Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Kunjal\_Patel](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kunjal_patel/32/121598_2.png) [@Kunjal\_Patel](https://discuss.elastic.co/u/Kunjal_Patel)\
**Post date:** [May 30, 2023, 1:33pm UTC](https://discuss.elastic.co/t/query-with-text-field/334687/1 "2023-05-30T13:33:42Z")

</div>

I have index settings and mappings are as below  
"settings": {  
"number\_of\_shards": 1,  
"number\_of\_replicas": 1,  
"index": {"max\_result\_window": 10000000, "max\_inner\_result\_window": 1000},  
"analysis": {  
"analyzer": {  
"custom\_analyzer": {  
"type": "custom",  
"tokenizer": "whitespace",  
"filter": ["lowercase", "stop", "asciifolding"],  
"char\_filter": ["html\_strip"],  
},  
"sort\_analyzer": {  
"type": "custom",  
"tokenizer": "keyword",  
"filter": ["lowercase", "asciifolding"],  
"char\_filter": ["html\_strip"],  
},  
}  
},  
},

"mappings": {  
"dynamic": "strict",  
"properties": {  
"uuid": {"type": "keyword"},  
"task\_number": {"type": "integer"},  
"task": {  
"type": "text",  
"fields": {"keyword": {"type": "keyword"}},  
"analyzer": "sort\_analyzer",  
"fielddata": True,  
}  
}

"task" : " Test User Data"  
now I need to create a search query where if the user search "ser" it can see this above string but if user added "Test User Data Test User Data" it won't be able to see the result

---

<div class="post-metadata">

**Author:** ![carly.richmond](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/carly.richmond/32/104935_2.png) [@carly.richmond](https://discuss.elastic.co/u/carly.richmond)\
**Post date:** [June 1, 2023, 9:44am UTC](https://discuss.elastic.co/t/query-with-text-field/334687/2 "2023-06-01T09:44:56Z")

</div>

Hi Kunjal,

Welcome to the community! Thanks for sharing your mapping and settings. Can you give more details on what fields the search terms are to be applied to?

I'm not quite clear what search you are trying to do. But I assume you want to include documents based on one criteria and exclude based on another, which would fit well with a [`bool` query](https://www.elastic.co/guide/en/elasticsearch/reference/8.8/query-dsl-bool-query.html), such as this:

```auto
GET santas-playlist/_search
{
  "query": {
    "bool": {
      "must": [
        {
          "term": {
            "title": "christmas"
          }
        }
      ],
      "must_not": [
        {
          "match_phrase": {
            "artist": "Chris Rea"
          }
        }
      ]
    }
  }
}

```

---

<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:** [June 29, 2023, 9:45am UTC](https://discuss.elastic.co/t/query-with-text-field/334687/3 "2023-06-29T09:45:27Z")

</div>

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