# Elasticsearch Combine Term and Match Phrase Query And Performance Issue

**URL:** <https://discuss.elastic.co/t/elasticsearch-combine-term-and-match-phrase-query-and-performance-issue/166277>\
**Category:** Elasticsearch\
**Created:** [January 30, 2019, 7:18am UTC](https://discuss.elastic.co/t/elasticsearch-combine-term-and-match-phrase-query-and-performance-issue/166277 "2019-01-30T07:18:10Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Eyup\_Can\_Arslan](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/eyup_can_arslan/32/46533_2.png) [@Eyup\_Can\_Arslan](https://discuss.elastic.co/u/Eyup_Can_Arslan)\
**Post date:** [January 30, 2019, 7:18am UTC](https://discuss.elastic.co/t/elasticsearch-combine-term-and-match-phrase-query-and-performance-issue/166277/1 "2019-01-30T07:18:10Z")

</div>

In the below, I shared a Elastic Search raw query. I used Elasticsearch 6.X verison.

In the given Elasticsearch Raw query that is above, I try to generate a result like this t-sql command in below.

_ **Here is T-Sql Command** _

```
Select * from where Departman=”IT” and CountryCoude=”US” and employeeName Like’Ey%’ and employeeSurname like’Ars%’ and birthdate>=’1991-01-01’

```

**Here is the Raw Query For Elasticsearch**

> Note:Departman and Country field marked as [keyword] to get exact  
> matching.

```
   {
  "size": 3,
  "query": {
    "bool": {
      "must": [
        {
          "match_phrase_prefix": {
            "employeeName": {
              "query": "Ey"
            }
          }
        },
        {
          "match_phrase_prefix": {
            "emplotyeSurname": {
              "query": "Ars"
            }
          }
        },
        {
          "range": {
            "birthday": {
              "gte": "1991-01-01T00:00:00"
            }
          }
        }
      ],
      "filter": [
        {
          "terms": {
            "Departman": [
              "IT"
            ]
          }
        },
        {
          "terms": {
            "CountyryCode": [
              "US"
            ]
          }
        }
      ]
    }
  }
}

```

I have a few question about this Elastic Search Query.

Firstly, I try to combine term and match query. Am I correct or do you have any advice for me?

At there I used filter keyword in departman and country . My aim is that use caching ability of Elasticsearch for filters via department and countryCode field. Is there Am I correct?

---

<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:** [February 27, 2019, 7:18am UTC](https://discuss.elastic.co/t/elasticsearch-combine-term-and-match-phrase-query-and-performance-issue/166277/2 "2019-02-27T07:18:22Z")

</div>

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