# Can I force Elasticseach to do a match\_phrase when filtering a field?

**URL:** <https://community.dremio.com/t/can-i-force-elasticseach-to-do-a-match-phrase-when-filtering-a-field/9575>\
**Category:** Dremio University\
**Created:** [August 19, 2022, 2:28pm UTC](https://community.dremio.com/t/can-i-force-elasticseach-to-do-a-match-phrase-when-filtering-a-field/9575 "2022-08-19T14:28:43Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![almirb](https://avatars.discourse-cdn.com/v4/letter/a/e9bcb4/32.png) [@almirb](https://community.dremio.com/u/almirb)\
**Post date:** [August 19, 2022, 2:28pm UTC](https://community.dremio.com/t/can-i-force-elasticseach-to-do-a-match-phrase-when-filtering-a-field/9575/1 "2022-08-19T14:28:43Z")

</div>

Hello Dremio friends!

I’m connecting Dremio to Elasticsearch v. 7.10.2.

```auto
{
  "version" : {
    "number" : "7.10.2",
    "build_flavor" : "oss",
    "build_type" : "rpm",
    "build_hash" : "---------------------------------",
    "build_date" : "2021-01-13T00:42:12.435326Z",
    "build_snapshot" : false,
    "lucene_version" : "8.7.0",
    "minimum_wire_compatibility_version" : "6.8.0",
    "minimum_index_compatibility_version" : "6.0.0-beta1"
  },
}

```

I have problems when making queries using ‘=’ or ‘IN’ to filter fields with more than one word… Can I force Elastic to use **match\_phrase** when filtering with Dremio SQL?

Also tried turning on the option _Use index/doc fields when pushing down aggregates and filters on analyzed and normalized fields (may produce unexpected results)_, but It really gives me unexpected results … is like Elastic is doing “OR” with the parts of the text I’m filtering. Need to search the entire phrase, like “Name Surname”. Example:

```auto
SELECT product_id
FROM ElasticSource.my_index
WHERE product_name IN ('My Complete Product Name1','My Complete Product Name2')

```

That query above is mixing the returned products on results.

The only way I could make that work is using **CONTAINS** … but the filtering line is gerated automatically on my software and I can’t change this behavior. That command bellow works well:

```auto
SELECT product_id
FROM ElasticSource.my_index
WHERE CONTAINS(product_name, ('"My Complete Product Name1"', '"My Complete Product Name2"')

```

But I need to add double quotes inside the simple quotes too.

Can someone help me on this?  
Thanks!

---

<div class="post-metadata">

**Author:** ![almirb](https://avatars.discourse-cdn.com/v4/letter/a/e9bcb4/32.png) [@almirb](https://community.dremio.com/u/almirb)\
**Post date:** [August 24, 2022, 11:30am UTC](https://community.dremio.com/t/can-i-force-elasticseach-to-do-a-match-phrase-when-filtering-a-field/9575/2 "2022-08-24T11:30:27Z")

</div>

Maybe this is happening because I’m connecting to ElasticSearch on Open Distro version. Apache Superset uses SQLAlchemy for connecting on ElasticSearch and it has one connector for each type of distribution.  
I think Dremio should have an option to differentiate between these two versions.  
[https://github.com/preset-io/elasticsearch-dbapi](https://github.com/preset-io/elasticsearch-dbapi)
