# Anomaly Detection DSL errors

**URL:** <https://forum.opensearch.org/t/anomaly-detection-dsl-errors/8096>\
**Category:** Machine Learning\
**Created:** [December 21, 2021, 12:56am UTC](https://forum.opensearch.org/t/anomaly-detection-dsl-errors/8096 "2021-12-21T00:56:38Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![adrian](https://avatars.discourse-cdn.com/v4/letter/a/82dd89/32.png) [@adrian](https://forum.opensearch.org/u/adrian)\
**Post date:** [December 21, 2021, 12:56am UTC](https://forum.opensearch.org/t/anomaly-detection-dsl-errors/8096/1 "2021-12-21T00:56:38Z")

</div>

I am trying to set up some anomaly detections. I have an index that has field `http.response.status_code`. This is a long and contains the HTTP status code.

I am trying to create a detector that will search my index, however, I am failing to achieve this ☹

If I go to Dev Tools, I am able to search my index. I have tried a few different ways

```auto
{
  "query": {
    "range": {
      "http.response.status_code": {
        "gte": 400,
        "lt": 500
      }
    }
  }
}

```

and

```auto
{
  "query": {
    "terms": {
      "http.response.status_code": [
        "400",
        "401",
        "200"
      ]
    }
  }
}

```

These all return documents, but when I use the same code under custom expression in AD I get an query error  
`Custom query error: [1:1309] [terms] unknown field [http.response.status_code]`

The end goal is that I am trying to set up a detector that will detect an increase in 4XX and 5XX which is in field http.response.status\_code

Any suggestions?

---

<div class="post-metadata">

**Author:** ![adrian](https://avatars.discourse-cdn.com/v4/letter/a/82dd89/32.png) [@adrian](https://forum.opensearch.org/u/adrian)\
**Post date:** [December 21, 2021, 3:31am UTC](https://forum.opensearch.org/t/anomaly-detection-dsl-errors/8096/2 "2021-12-21T03:31:38Z")

</div>

Think I worked it out. I was adding the filtering in the one wrong place.

When setting up the `Data Source`, you can add a `Data filter`, this is where you can add filters based on status codes.  
I created 2 ADs. One with the Data filter looking for 4XX and another looking 5XX.

Hopefully, this will help someone else.
