# Elastic query for where in

**URL:** <https://discuss.elastic.co/t/elastic-query-for-where-in/313104>\
**Category:** Elasticsearch\
**Created:** [August 28, 2022, 5:26pm UTC](https://discuss.elastic.co/t/elastic-query-for-where-in/313104 "2022-08-28T17:26:23Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Harrowmykel](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/harrowmykel/32/110167_2.png) [@Harrowmykel](https://discuss.elastic.co/u/Harrowmykel)\
**Post date:** [August 28, 2022, 5:26pm UTC](https://discuss.elastic.co/t/elastic-query-for-where-in/313104/1 "2022-08-28T17:26:23Z")

</div>

Hello,

Can someone give me the json query equivalent of the following MySQL query

Select \* from Table where col1=q or col2=q where cat in (cat1, cat2, cat3)

Basically I want to find "q" in index "Table" but restricted documents that belong to a certain category "cat1", "cat2", cat3. I want to search in fields col1 and col2

![20220827_010842](https://us1.discourse-cdn.com/elastic/original/3X/0/d/0d71c71310830e618d104840b6d13ced15b6545b.png)

---

<div class="post-metadata">

**Author:** ![RabBit\_BR](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rabbit_br/32/82261_2.png) [@RabBit\_BR](https://discuss.elastic.co/u/RabBit_BR)\
**Post date:** [August 28, 2022, 6:53pm UTC](https://discuss.elastic.co/t/elastic-query-for-where-in/313104/2 "2022-08-28T18:53:49Z")

</div>

Hi @Harrowmykel .

My suggestion:

```auto
{
  "query": {
    "bool": {
      "filter": {
        "terms": {
          "cat": [
            "a",
            "a"
          ]
        }
      },
      "should": [
        {
          "match": {
            "col_1": "q"
          }
        },
        {
          "match": {
            "col_2": "q"
          }
        }
      ]
    }
  }
}

```

Read more about [bool queries](https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-bool-query.html).

---

<div class="post-metadata">

**Author:** ![Harrowmykel](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/harrowmykel/32/110167_2.png) [@Harrowmykel](https://discuss.elastic.co/u/Harrowmykel)\
**Post date:** [August 28, 2022, 7:07pm UTC](https://discuss.elastic.co/t/elastic-query-for-where-in/313104/3 "2022-08-28T19:07:32Z")

</div>

Thanks a lot for the response @RabBit_BR . How can I make it case-insensitive and also fuzzy? So that it is also spelling-error tolerant?

---

<div class="post-metadata">

**Author:** ![xeraa](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/xeraa/32/48181_2.png) [@xeraa](https://discuss.elastic.co/u/xeraa)\
**Post date:** [August 28, 2022, 7:34pm UTC](https://discuss.elastic.co/t/elastic-query-for-where-in/313104/4 "2022-08-28T19:34:30Z")

</div>

`text` fields are by default case-insensitive and `match` has a parameter `fuzziness`. But for a more detailed answer you'll need to provide some sample documents with specifics what should and shouldn't match.

PS: No screenshots of code and format your code, please.

---

<div class="post-metadata">

**Author:** ![Harrowmykel](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/harrowmykel/32/110167_2.png) [@Harrowmykel](https://discuss.elastic.co/u/Harrowmykel)\
**Post date:** [August 28, 2022, 8:06pm UTC](https://discuss.elastic.co/t/elastic-query-for-where-in/313104/5 "2022-08-28T20:06:28Z")

</div>

Hello @xeraa

When I search I want to only search documents with category\_shortcode 'yoruba' and I would like a case insensitive and spelling error tolerant selection

This is what a document looks like

```auto

                "_source": {
                    "id": "54",
                    "video_title": "Wuraola",
                    "shortcode": "54-wuraola",
                    "description": "Doyin blesses every person she comes along with but she's a sickler. She leaves her home when she realises she is unwanted and comes in contact with some people whom she blessed. Now that her Father is feeling her absence, he wants her back so also the other people too her desperate to have Doyin. \n\n FOLLOW on IG. TW and FB: @YORUBAHOOD\n\nTo enjoy more of our movies, click here: https:\/\/www.youtube.com\/user\/modexy234",
                    "youtube_id": "sC31YGEjYCw",
                    "duration": "5985",
                    "formatted_duration": "01:39:45",
                    "channel_id": "3",
                    "favorite_count": "174",
                    "comments_count": "62",
                    "views_count": "174",
                    "dislike_count": "0",
                    "rating": "174",
                    "is_trailer": "0",
                    "last_refresh_time": "1660939202",
                    "original_title": "Wuraola - Latest Yoruba Movie Drama 2016",
                    "active": "1",
                    "deleted_on_youtube": "0",
                    "original_description": "Doyin blesses every person she comes along with but she's a sickler. She leaves her home when she realises she is unwanted and comes in contact with some people whom she blessed. Now that her Father is feeling her absence, he wants her back so also the other people too her desperate to have Doyin. \n\n FOLLOW on IG. TW and FB: @YORUBAHOOD\n\nTo enjoy more of our movies, click here: https:\/\/www.youtube.com\/user\/modexy234",
                    "tags": "TheOkintv,irokotv|NOLLYWOOD,Yoruba 2016 Latest Movies,Yoruba5star Nollywood Movies,Yorubamagic 2016,Realnollymovie,Newly Uploaded 2016 Yoruba Movies,inside ibakatv 2016,iBAKATV|YORUBA,iBAKATV|NOLLYWOOD,TheOkintv Latest Yoruba 2016 Movie,Nollywood PicturesTV,Nigerian Yoruba Nollywood Movies,OlekuTV,ApataTV+,Geledetvhits,Latest Yoruba 2016 Movies,Oleku Tv Latest Yoruba Movie LibraTV,Latest Yoruba Movie 2016 Releases This Week,GeledeTV+,LibraTV",
                    "create_time": "1660939202",
                    "youtube_create_time": "1476434296",
                    "category_shortcodes": [
                        "drama",
                        "yoruba",
                        "romantic",
                        "intriguing",
                        "2016"
                    ],
                    "category_ids": [
                        "2",
                        "3",
                        "4",
                        "8",
                        "13"
                    ],
                    "actor_shortcodes": [
                        "drama",
                        "yoruba",
                        "romantic",
                        "intriguing",
                        "2016"
                    ],
                    "actor_ids": [
                        "2",
                        "3",
                        "4",
                        "8",
                        "13"
                    ]
                }

```

---

<div class="post-metadata">

**Author:** ![Harrowmykel](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/harrowmykel/32/110167_2.png) [@Harrowmykel](https://discuss.elastic.co/u/Harrowmykel)\
**Post date:** [August 28, 2022, 8:59pm UTC](https://discuss.elastic.co/t/elastic-query-for-where-in/313104/6 "2022-08-28T20:59:22Z")

</div>

I found the solutions here

> **[r/elasticsearch - How to filter a multi match query?](https://www.reddit.com/r/elasticsearch/comments/ss9g6n/how_to_filter_a_multi_match_query/)**
>
> 3 votes and 3 comments so far on Reddit

for my case this was it

```auto
{
    "query": {
        "bool": {
            "must": [
                {
                    "multi_match": {
                        "fields": [
                            "col1",
                            "col2",
                            "col3"
                        ],
                        "query": "q",
                        "fuzziness": "AUTO"
                    }
                }
            ],
            "filter": [
                {
                    "terms": {
                        "cat": [
                            "a", 
                            "b"
                        ]
                    }
                },
            ]
        }
    }
}

```

---

<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:** [September 25, 2022, 8:59pm UTC](https://discuss.elastic.co/t/elastic-query-for-where-in/313104/7 "2022-09-25T20:59:37Z")

</div>

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