# Query with Bool Must and Contain String

**URL:** <https://discuss.elastic.co/t/query-with-bool-must-and-contain-string/130311>\
**Category:** Elasticsearch\
**Created:** [May 2, 2018, 6:49pm UTC](https://discuss.elastic.co/t/query-with-bool-must-and-contain-string/130311 "2018-05-02T18:49:34Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![TomTom](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/tomtom/32/3676_2.png) [@TomTom](https://discuss.elastic.co/u/TomTom)\
**Post date:** [May 2, 2018, 6:49pm UTC](https://discuss.elastic.co/t/query-with-bool-must-and-contain-string/130311/1 "2018-05-02T18:49:35Z")

</div>

How can I create a JSON that returns the results in this type of condition?

```
User_ID = 1234 
AND Type_Search IN ('ALL', 'RESTRICT') 
AND (
title contains 'example string' 
OR 
content contains 'example string'
)

```

I create this JSON, but i don't know how search the string columns and this example don't return data:

```
{
"query": {
    "bool": {
        "must":
            [
                {
                    "term": {
                        "user_id": 14492
                    }
                },
                {
                    "terms": {
                        "type_search": [
                            "ALL",
                            "RESTRICT"
                        ]
                    }
                },
                {
                    "match": {
                        "title": "Modes"
                    }
                },
                {
                    "match": {
                        "content": "Modes"
                    }
                }
            ]
        }
    }
}
```

---

<div class="post-metadata">

**Author:** ![TomTom](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/tomtom/32/3676_2.png) [@TomTom](https://discuss.elastic.co/u/TomTom)\
**Post date:** [May 2, 2018, 7:24pm UTC](https://discuss.elastic.co/t/query-with-bool-must-and-contain-string/130311/2 "2018-05-02T19:24:01Z")

</div>

Problem solved.  
Change the type of title and content to **text** , instead **keyword**.

Alter the JSON to:

```
{
"query": {
    "bool": {
        "must":
            [
                {
                    "term": {
                        "user_id": 14492
                    }
                },
                {
                    "terms": {
                        "type_search": [
                            "ALL",
                            "RESTRICT"
                        ]
                    }
                },{
			"query_string" : {
			       "fields" : ["title", "content"],
				"query" : "modes"
				}
			}
                }
}
```

---

<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 30, 2018, 7:24pm UTC](https://discuss.elastic.co/t/query-with-bool-must-and-contain-string/130311/3 "2018-05-30T19:24:03Z")

</div>

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