# Query a AND b

**URL:** <https://discuss.elastic.co/t/query-a-and-b/225816>\
**Category:** Elasticsearch\
**Created:** [March 31, 2020, 8:30am UTC](https://discuss.elastic.co/t/query-a-and-b/225816 "2020-03-31T08:30:20Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![sancho](https://avatars.discourse-cdn.com/v4/letter/s/5daacb/32.png) [@sancho](https://discuss.elastic.co/u/sancho)\
**Post date:** [March 31, 2020, 8:30am UTC](https://discuss.elastic.co/t/query-a-and-b/225816/1 "2020-03-31T08:30:20Z")

</div>

Hi everyone,

My goal is to make a search engine for my data that look like "ta AND tb OR (tc AND td)"

I'm focusing on the part "ta AND tb".

```auto
{
      "id": 1,
      "keywords": ["java", "node", "PHP"]
    },
    {
      "id": 2,
      "keywords": ["javascript", "node", "PHP"]
    },
    {
      "id": 3,
      "keywords": ["java", "node.js", "PHP"]
    },
    {
      "id": 4,
      "keywords": ["java/j2ee", "node", "PHP"]
    },
    {
      "id": 5,
      "keywords": ["java node", "spring", "PHP"]
    }

```

With the query "java AND node". I'd like to have the 1, 3, 5, 4 then 2.

I try with

```auto
     {
      "query": {
        "bool": {
          "must": [
            {
              "multi_match": {
                "query": "java",
                "fields": [
                  "keywords^5",
                  "keywords.ngram"
                ]
              },
              "multi_match": {
                "query": "node",
                "fields": [
                  "keywords^5",
                  "keywords.ngram"
                ]
              }
            }
          ]
        }
      }
    }

```

and with

```auto
    {
      "query": {
        "bool": {
          "must": [
            {
              "match_phrase": {
                "keywords": "java"
              }
            },
            {
              "match_phrase": {
                "keywords": "node"
              }
            }
          ]
        }
      }
    }

```

I use a tokenizer with ngram (min: 1, max 40, token\_chars: [letter, digit]

How could I perform my request as I expect? Do you any documentation I could use and tips?

Thanks for reading.

---

<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:** [April 28, 2020, 8:30am UTC](https://discuss.elastic.co/t/query-a-and-b/225816/2 "2020-04-28T08:30:30Z")

</div>

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