# How to filter result with python script file

**URL:** https://discuss.elastic.co/t/how-to-filter-result-with-python-script-file/107882
**Category:** Elasticsearch
**Created:** [November 16, 2017, 8:41am UTC](https://discuss.elastic.co/t/how-to-filter-result-with-python-script-file/107882 "2017-11-16T08:41:38Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![MengPhantom](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mengphantom/32/24265_2.png) [@MengPhantom](https://discuss.elastic.co/u/MengPhantom)
#### Post date: [November 16, 2017, 8:41am UTC](https://discuss.elastic.co/t/how-to-filter-result-with-python-script-file/107882/1 "2017-11-16T08:41:39Z")

</div>

I want filter search result with my local python script,I have try es2.4 's python script file ,It won't work even call a simple function.What should I do?

---

<div class="post-metadata">

### Author: ![warkolm](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/warkolm/32/39224_2.png) [@warkolm](https://discuss.elastic.co/u/warkolm)
#### Post date: [November 16, 2017, 9:16am UTC](https://discuss.elastic.co/t/how-to-filter-result-with-python-script-file/107882/2 "2017-11-16T09:16:01Z")

</div>

Providing more info would be helpful.

> [@MengPhantom](#):
>
> It won't work even I call a simple function

What does that mean?

> [@MengPhantom](#):
>
> even I call a simple function

What does the function look like?

---

<div class="post-metadata">

### Author: ![MengPhantom](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mengphantom/32/24265_2.png) [@MengPhantom](https://discuss.elastic.co/u/MengPhantom)
#### Post date: [November 17, 2017, 7:00am UTC](https://discuss.elastic.co/t/how-to-filter-result-with-python-script-file/107882/3 "2017-11-17T07:00:15Z")

</div>

@warkolm  
I write a python script just below ,

```auto
def boo(pid):
    if pid>200:
         return True
    return False 
boo(doc['pid'].value)==True

```

it doesn't work, and below script can work

```auto
doc['pid'].value>200

```

---

<div class="post-metadata">

### Author: ![warkolm](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/warkolm/32/39224_2.png) [@warkolm](https://discuss.elastic.co/u/warkolm)
#### Post date: [November 17, 2017, 7:40am UTC](https://discuss.elastic.co/t/how-to-filter-result-with-python-script-file/107882/4 "2017-11-17T07:40:24Z")

</div>

Where are you running this?

---

<div class="post-metadata">

### Author: ![MengPhantom](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mengphantom/32/24265_2.png) [@MengPhantom](https://discuss.elastic.co/u/MengPhantom)
#### Post date: [November 17, 2017, 8:45am UTC](https://discuss.elastic.co/t/how-to-filter-result-with-python-script-file/107882/5 "2017-11-17T08:45:59Z")

</div>

@warkolm  
I put it below `elasticsearch2.4/config/scripts/test.py`,and query like this

```auto
{
  "query": {
    "match_all": {}
  },
  "post_filter": {
    "script": {
      "script": {
        "lang": "python",
        "file":"test"
      }
    }
  }
}

```

---

<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: [December 15, 2017, 8:46am UTC](https://discuss.elastic.co/t/how-to-filter-result-with-python-script-file/107882/6 "2017-12-15T08:46:20Z")

</div>

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