# Regexp "@" and ".\*&.\*" matches with everything

**URL:** https://forum.opensearch.org/t/regexp-and-matches-with-everything/14507
**Category:** Reporting Plugin
**Created:** [May 31, 2023, 4:55am UTC](https://forum.opensearch.org/t/regexp-and-matches-with-everything/14507 "2023-05-31T04:55:09Z")
**Posts on this page:** 9
**Page:** 1

<div class="post-metadata">

### Author: ![rahul7822](https://avatars.discourse-cdn.com/v4/letter/r/9d8465/32.png) [@rahul7822](https://forum.opensearch.org/u/rahul7822)
#### Post date: [May 31, 2023, 4:55am UTC](https://forum.opensearch.org/t/regexp-and-matches-with-everything/14507/1 "2023-05-31T04:55:09Z")

</div>

# OpenSearch 1.3

My query in the opensearch “dev\_tools” is as below, it’s matches with everything:

```auto
{
  "query": {
    "bool": {
      "must": [
        {
          "regexp": {
            "search_field.keyword": "@"
          }
        }
      ]
    }
  }
}

```

Additionally regexp : ._&._ also matches with everything

```auto
{
  "query": {
    "bool": {
      "must": [
        {
          "regexp": {
            "search_field.keyword": ".*&.*"
          }
        }
      ]
    }
  }
}

```

Could someone explain why It’s returning everything in the above two scenarios.  
Any suggestion to improve the query with explanation will be appreciated.  
Have anyone faced such type problems in opensearch?

Thanks

---

<div class="post-metadata">

### Author: ![Gsmitt](https://sea1.discourse-cdn.com/flex019/user_avatar/forum.opensearch.org/gsmitt/32/1718_2.png) [@Gsmitt](https://forum.opensearch.org/u/Gsmitt)
#### Post date: [June 2, 2023, 3:54am UTC](https://forum.opensearch.org/t/regexp-and-matches-with-everything/14507/2 "2023-06-02T03:54:27Z")

</div>

Hey @rahul7822

I used this, it seamed to work.

```auto
GET /_search
{
  "query": {
    "bool": {
      "must": [
        {
          "regexp": {
            "message.keyword": "@"
          }
        }
      ]
    }
  }
}

```

---

<div class="post-metadata">

### Author: ![rahul7822](https://avatars.discourse-cdn.com/v4/letter/r/9d8465/32.png) [@rahul7822](https://forum.opensearch.org/u/rahul7822)
#### Post date: [June 2, 2023, 4:18am UTC](https://forum.opensearch.org/t/regexp-and-matches-with-everything/14507/3 "2023-06-02T04:18:20Z")

</div>

Hi @Gsmitt,  
Thanks for you response.  
It’s strange behavior in my case. My mapping for the index is as below

```auto
{
  "booktransactions": {
    "mappings": {
      "properties": {
        "author": {
          "type": "text",
          "fields": {
            "keyword": {
              "type": "keyword"
            }
          }
        },
        "bookDesc": {
          "type": "text"
        },
        "bookId": {
          "type": "text"
        },
        "bookName": {
          "type": "text",
          "fields": {
            "keyword": {
              "type": "keyword"
            }
          }
        },
        "gender": {
          "type": "text",
          "fields": {
            "keyword": {
              "type": "keyword"
            }
          }
        },
        "price": {
          "type": "double"
        },
        "publishedDate": {
          "type": "date"
        }
      }
    }
  }
}

```

The query I execute is as below:

```auto
GET booktransactions/_search
{
  "query": {
    "bool": {
      "must": [
        {
          "regexp": {
            "gender.keyword": "@"
          }
        }
      ]
    }
  }
}

```

Result : I get all the hits/documents from the index

```auto
"took": 23,
  "timed_out": false,
  "_shards": {
    "total": 5,
    "successful": 5,
    "skipped": 0,
    "failed": 0
  },
  "hits": {
    "total": {
      "value": 20,
      "relation": "eq"
    },
    "max_score": 1,

```

---

<div class="post-metadata">

### Author: ![Gsmitt](https://sea1.discourse-cdn.com/flex019/user_avatar/forum.opensearch.org/gsmitt/32/1718_2.png) [@Gsmitt](https://forum.opensearch.org/u/Gsmitt)
#### Post date: [June 2, 2023, 10:03pm UTC](https://forum.opensearch.org/t/regexp-and-matches-with-everything/14507/4 "2023-06-02T22:03:45Z")

</div>

hey @rahul7822

Did some testing in my lab, That search query did not work , But I tried this and received good results.

```auto
GET /winlogbeat-2023.06.02/_search
{
  "query": {
    "regexp": {
      "message": "off"
    }
  }
}

```

But the `"@" and "&"` did not work so well. So Im not 100% sure whats up, perhaps its the symbols.

---

<div class="post-metadata">

### Author: ![kris](https://sea1.discourse-cdn.com/flex019/user_avatar/forum.opensearch.org/kris/32/2208_2.png) [@kris](https://forum.opensearch.org/u/kris)
#### Post date: [June 5, 2023, 5:57pm UTC](https://forum.opensearch.org/t/regexp-and-matches-with-everything/14507/5 "2023-06-05T17:57:26Z")

</div>

odd - @wbeckler @seanneumann - do you know of any gotchas with the `"@" and "&"` symbols?

---

<div class="post-metadata">

### Author: ![wbeckler](https://avatars.discourse-cdn.com/v4/letter/w/9d8465/32.png) [@wbeckler](https://forum.opensearch.org/u/wbeckler)
#### Post date: [June 6, 2023, 5:20pm UTC](https://forum.opensearch.org/t/regexp-and-matches-with-everything/14507/6 "2023-06-06T17:20:05Z")

</div>

I’m not sure what the regex rules are ☹

---

<div class="post-metadata">

### Author: ![AMoo-Miki](https://sea1.discourse-cdn.com/flex019/user_avatar/forum.opensearch.org/amoo-miki/32/4642_2.png) [@AMoo-Miki](https://forum.opensearch.org/u/AMoo-Miki)
#### Post date: [June 6, 2023, 9:48pm UTC](https://forum.opensearch.org/t/regexp-and-matches-with-everything/14507/7 "2023-06-06T21:48:37Z")

</div>

By default, all “Optional Operators” are enabled in Regular Expression queries executed on OpenSearch where `&` is the “intersection” operator. Saying `.*&.*` means anything that matches `.*` and also matches `.*`. As a result you get all items returned.

As you have discovered, `@` means “anystring”.

To turn those optional operators off, you can use this:

```auto
   ...
        {
          "regexp": {
            "message.keyword": {
              "value": ".*&.*",
              "flags": "NONE"
            }
          }
        }
   ...

```

---

<div class="post-metadata">

### Author: ![Gsmitt](https://sea1.discourse-cdn.com/flex019/user_avatar/forum.opensearch.org/gsmitt/32/1718_2.png) [@Gsmitt](https://forum.opensearch.org/u/Gsmitt)
#### Post date: [June 6, 2023, 10:50pm UTC](https://forum.opensearch.org/t/regexp-and-matches-with-everything/14507/8 "2023-06-06T22:50:53Z")

</div>

Awesome, Thanks @AMoo-Miki

---

<div class="post-metadata">

### Author: ![kris](https://sea1.discourse-cdn.com/flex019/user_avatar/forum.opensearch.org/kris/32/2208_2.png) [@kris](https://forum.opensearch.org/u/kris)
#### Post date: [June 7, 2023, 2:33pm UTC](https://forum.opensearch.org/t/regexp-and-matches-with-everything/14507/9 "2023-06-07T14:33:11Z")

</div>

thank you @AMoo-Miki!!
