# Logstash having problem with elasticsearch filter

**URL:** <https://discuss.elastic.co/t/logstash-having-problem-with-elasticsearch-filter/224235>\
**Category:** Logstash\
**Created:** [March 19, 2020, 9:15am UTC](https://discuss.elastic.co/t/logstash-having-problem-with-elasticsearch-filter/224235 "2020-03-19T09:15:53Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![zozo6015](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/zozo6015/32/12117_2.png) [@zozo6015](https://discuss.elastic.co/u/zozo6015)\
**Post date:** [March 19, 2020, 9:15am UTC](https://discuss.elastic.co/t/logstash-having-problem-with-elasticsearch-filter/224235/1 "2020-03-19T09:15:54Z")

</div>

Hello,

In the logstash pipeline I am querying the same index to get some data from the previous day

The code looks like this:

```auto
    elasticsearch {
    	hosts => ["127.0.0.1:9200"]
    	index => "index"
    	query => "country_region:%{[country_region]}"
    	enable_sort => true
    	sort => "@timestamp:desc"
    	result_size => 1
    	fields => [{"sold" => "sold_yesterday"},{"viewed" => "viewed_yesterday"}]
    }

```

However in the logs I can see the following:

```
[2020-03-19T05:12:44,531][WARN][logstash.filters.elasticsearch][main] Failed to query elasticsearch for previous event {:index=>"index", :error=>"undefined method `start_with?' for {\"sold\"=>\"sold_yesterday\"}:Hash"}

```

What I am doing wrong?

---

<div class="post-metadata">

**Author:** ![Badger](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/badger/32/25190_2.png) [@Badger](https://discuss.elastic.co/u/Badger)\
**Post date:** [March 22, 2020, 4:18pm UTC](https://discuss.elastic.co/t/logstash-having-problem-with-elasticsearch-filter/224235/2 "2020-03-22T16:18:57Z")

</div>

I realize that fields is documented as taking an array, and code itself requires that, but normal usage is to pass a hash and rely on the automatic conversion of the hash to an array. This is actually pretty common in logstash. Does it work better if you try

```
fields => {
    "sold" => "sold_yesterday"
    "viewed" => "viewed_yesterday"
}
```

---

<div class="post-metadata">

**Author:** ![zozo6015](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/zozo6015/32/12117_2.png) [@zozo6015](https://discuss.elastic.co/u/zozo6015)\
**Post date:** [March 23, 2020, 7:00pm UTC](https://discuss.elastic.co/t/logstash-having-problem-with-elasticsearch-filter/224235/3 "2020-03-23T19:00:21Z")

</div>

Any idea how to set the field type? They are numbers but I can see them set as string while I need to do some math functions and I cannot do them unless they are int type:

---

<div class="post-metadata">

**Author:** ![Badger](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/badger/32/25190_2.png) [@Badger](https://discuss.elastic.co/u/Badger)\
**Post date:** [March 23, 2020, 7:11pm UTC](https://discuss.elastic.co/t/logstash-having-problem-with-elasticsearch-filter/224235/4 "2020-03-23T19:11:28Z")

</div>

If you are referring to the fields that the elasticsearch filter adds then try mutate+convert.

---

<div class="post-metadata">

**Author:** ![zozo6015](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/zozo6015/32/12117_2.png) [@zozo6015](https://discuss.elastic.co/u/zozo6015)\
**Post date:** [March 23, 2020, 7:23pm UTC](https://discuss.elastic.co/t/logstash-having-problem-with-elasticsearch-filter/224235/5 "2020-03-23T19:23:05Z")

</div>

I remembered in meantime about the mutate-\> convert. I was hoping that there is a way to directly map the field type directly from the elasticsearch filter. Thanks anyways

---

<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 20, 2020, 7:23pm UTC](https://discuss.elastic.co/t/logstash-having-problem-with-elasticsearch-filter/224235/6 "2020-04-20T19:23:13Z")

</div>

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