# Search query with keywords who use AND, OR and quotes

**URL:** <https://discuss.elastic.co/t/search-query-with-keywords-who-use-and-or-and-quotes/184367>\
**Category:** Elasticsearch\
**Created:** [June 5, 2019, 1:29pm UTC](https://discuss.elastic.co/t/search-query-with-keywords-who-use-and-or-and-quotes/184367 "2019-06-05T13:29:43Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![yan014](https://avatars.discourse-cdn.com/v4/letter/y/278dde/32.png) [@yan014](https://discuss.elastic.co/u/yan014)\
**Post date:** [June 5, 2019, 1:29pm UTC](https://discuss.elastic.co/t/search-query-with-keywords-who-use-and-or-and-quotes/184367/1 "2019-06-05T13:29:43Z")

</div>

Hello,

I'm working on a search engine with Elasticsearch, I have keywords and excluded keywords.

I would like to use quotes, AND and OR in my two inputs for advanced search.

Here's what I'm trying:

Keywords:

```auto
"foo bar" AND lorem OR ipsum

```

```json
{
    "body": {
        "query": {
            "bool": {
                "should": [
                    {
                        "bool": {
                            "must": [
                                {
                                    "multi_match": {
                                        "query": "foo bar",
                                        "type": "phrase",
                                        "fields": [
                                            "content",
                                            "title"
                                        ]
                                    }
                                },
                                {
                                    "multi_match": {
                                        "query": "lorem",
                                        "fields": [
                                            "content",
                                            "title"
                                        ]
                                    }
                                }
                            ]
                        }
                    },
                    {
                        "bool": {
                            "must": [
                                {
                                    "multi_match": {
                                        "query": "ipsum",
                                        "fields": [
                                            "content",
                                            "title"
                                        ]
                                    }
                                }
                            ]
                        }
                    }
                ]
            }
        }
    }
}

```

Results:

```auto
"lorem foo bar" => true
"foo bar" => false
"ipsum foo bar" => true

```

It works but is it the right way?

For the excluded keywords, I don't know how to add into this with the same system.

Example of what I'm expecting :

Excluded keywords:

```auto
"test AND test2 OR test3"

```

```auto
"lorem foo bar" => true
"lorem foo bar test" => true
"lorem foo bar test3" => false
"test lorem foo bar test2" => false

```

---

<div class="post-metadata">

**Author:** ![yan014](https://avatars.discourse-cdn.com/v4/letter/y/278dde/32.png) [@yan014](https://discuss.elastic.co/u/yan014)\
**Post date:** [June 8, 2019, 11:05am UTC](https://discuss.elastic.co/t/search-query-with-keywords-who-use-and-or-and-quotes/184367/2 "2019-06-08T11:05:02Z")

</div>

Hello 🙂

Any suggestions ?

---

<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, 2019, 11:05am UTC](https://discuss.elastic.co/t/search-query-with-keywords-who-use-and-or-and-quotes/184367/3 "2019-07-06T11:05:05Z")

</div>

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