# Delete by query not working

**URL:** <https://discuss.elastic.co/t/delete-by-query-not-working/267652>\
**Category:** Elasticsearch\
**Created:** [March 18, 2021, 12:16pm UTC](https://discuss.elastic.co/t/delete-by-query-not-working/267652 "2021-03-18T12:16:33Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sandeep\_Raju](https://avatars.discourse-cdn.com/v4/letter/s/8797f3/32.png) [@Sandeep\_Raju](https://discuss.elastic.co/u/Sandeep_Raju)\
**Post date:** [March 18, 2021, 12:16pm UTC](https://discuss.elastic.co/t/delete-by-query-not-working/267652/1 "2021-03-18T12:16:33Z")

</div>

Hi all,

I have an index with documents of username : 220987,220388,1218383.

I want to delete all documents with username starting with 22.

So i used below code:

```auto
POST /snmp-ser-my-thyalytics-com/_delete_by_query
{
   "query":{
"match":{
"username" : "22*"
	}
}
  
}

```

It executes the query, gives below output.

```auto
{
  "took" : 0,
  "timed_out" : false,
  "total" : 0,
  "deleted" : 0,
  "batches" : 0,
  "version_conflicts" : 0,
  "noops" : 0,
  "retries" : {
    "bulk" : 0,
    "search" : 0
  },
  "throttled_millis" : 0,
  "requests_per_second" : -1.0,
  "throttled_until_millis" : 0,
  "failures" : []
}

```

but there are no changes.I'm not able to figure out.

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [March 18, 2021, 12:44pm UTC](https://discuss.elastic.co/t/delete-by-query-not-working/267652/2 "2021-03-18T12:44:13Z")

</div>

It probably depends on the analyzer.

Note that the match query does not support wildcard I believe. May be a wildcard query would be better?

BTW I recommend testing this with a `_search` before going to the delete by query road.

---

<div class="post-metadata">

**Author:** ![Sandeep\_Raju](https://avatars.discourse-cdn.com/v4/letter/s/8797f3/32.png) [@Sandeep\_Raju](https://discuss.elastic.co/u/Sandeep_Raju)\
**Post date:** [March 18, 2021, 12:55pm UTC](https://discuss.elastic.co/t/delete-by-query-not-working/267652/3 "2021-03-18T12:55:19Z")

</div>

Hi,

i tested with one of the values it is working:

```auto
GET /snmp-ser-my-thyalytics-com/_search
{
  "query": {
    "match": {
      "username": "227095"
    }
  }
}

```

I am able to see the 4 hits associated with the value.

But when i try to use wildcard username: "22\*", there seems to be a problem.

When i try:

```auto
GET /snmp-ser-my-thyalytics-com/_search
{
  "query": {
    "match": {
      "username": "22*"
    }
  }
}

```

I get the following result:

```auto
{
  "took" : 0,
  "timed_out" : false,
  "_shards" : {
    "total" : 1,
    "successful" : 1,
    "skipped" : 0,
    "failed" : 0
  },
  "hits" : {
    "total" : {
      "value" : 0,
      "relation" : "eq"
    },
    "max_score" : null,
    "hits" : []
  }
}

```

Any turnaround or convention or way to query for this?

---

<div class="post-metadata">

**Author:** ![Sandeep\_Raju](https://avatars.discourse-cdn.com/v4/letter/s/8797f3/32.png) [@Sandeep\_Raju](https://discuss.elastic.co/u/Sandeep_Raju)\
**Post date:** [March 18, 2021, 1:24pm UTC](https://discuss.elastic.co/t/delete-by-query-not-working/267652/4 "2021-03-18T13:24:02Z")

</div>

I got it!

After much trial, I got the desired result:

I used prefix instead of match

```auto
POST /snmp-ser-my-thyalytics-com/_delete_by_query
{
  "query": {
    "prefix": {
      "username": "23"
    }
  }
}

```

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [March 19, 2021, 3:10am UTC](https://discuss.elastic.co/t/delete-by-query-not-working/267652/5 "2021-03-19T03:10:24Z")

</div>

As I said the `match` query does not support wildcards but the `wildcard` query does.

---

<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:** [April 16, 2021, 3:11am UTC](https://discuss.elastic.co/t/delete-by-query-not-working/267652/6 "2021-04-16T03:11:23Z")

</div>

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