# Opensearch and search with and operator

**URL:** <https://forum.opensearch.org/t/opensearch-and-search-with-and-operator/20075>\
**Category:** OpenSearch\
**Created:** [June 30, 2024, 11:53am UTC](https://forum.opensearch.org/t/opensearch-and-search-with-and-operator/20075 "2024-06-30T11:53:44Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![m\_pahlevanzadeh](https://sea1.discourse-cdn.com/flex019/user_avatar/forum.opensearch.org/m_pahlevanzadeh/32/7468_2.png) [@m\_pahlevanzadeh](https://forum.opensearch.org/u/m_pahlevanzadeh)\
**Post date:** [June 30, 2024, 11:53am UTC](https://forum.opensearch.org/t/opensearch-and-search-with-and-operator/20075/1 "2024-06-30T11:53:44Z")

</div>

I use opensearchpy module and search function. I have field x and field y.  
I want to write a search with IF‌ X=2 AND Y=3 return record(doc).  
Please help me to write this search.

---

<div class="post-metadata">

**Author:** ![gaobinlong](https://sea1.discourse-cdn.com/flex019/user_avatar/forum.opensearch.org/gaobinlong/32/5242_2.png) [@gaobinlong](https://forum.opensearch.org/u/gaobinlong)\
**Post date:** [July 1, 2024, 2:33am UTC](https://forum.opensearch.org/t/opensearch-and-search-with-and-operator/20075/2 "2024-07-01T02:33:04Z")

</div>

Just like this:

```auto
query = {
  "query": {
    "bool": {
      "must": [
        {
          "term": {
            "x": 2
          }
        },
        {
          "term": {
            "y": 3
          }
        }
      ]
    }
  }
}

response = client.search(
    body = query,
    index = 'your-index'
)

```
