# Python DSL syntax

**URL:** <https://discuss.elastic.co/t/python-dsl-syntax/93582>\
**Category:** Elasticsearch\
**Created:** [July 18, 2017, 12:48pm UTC](https://discuss.elastic.co/t/python-dsl-syntax/93582 "2017-07-18T12:48:15Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![rugenl](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rugenl/32/12887_2.png) [@rugenl](https://discuss.elastic.co/u/rugenl)\
**Post date:** [July 18, 2017, 12:48pm UTC](https://discuss.elastic.co/t/python-dsl-syntax/93582/1 "2017-07-18T12:48:15Z")

</div>

I have a working search consisting of the first 3 lines of this:  
= Search(using=client, index="exchange-\*")   
.query("match", type="iis")   
.filter("range", \*\* {'@timestamp': {'gte': 'now-1440m', 'lt': 'now'}})   
.exclude("match", geoip.country\_name="United States")

Adding the 4th line, causes this syntax error.

```
.exclude("match", geoip.country_name="United States")
                 ^

```

SyntaxError: keyword can't be an expression

I can't find an example of the proper syntax, I guess [geoip.xxx](http://geoip.xxx) is called a composite field?

Be gentile, I'm fairly new to elasticsearch, I've used python a lot, but for pretty simple things. I try to make all problem simple....

Thanks

---

<div class="post-metadata">

**Author:** ![danielmitterdorfer](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/danielmitterdorfer/32/110510_2.png) [@danielmitterdorfer](https://discuss.elastic.co/u/danielmitterdorfer)\
**Post date:** [July 21, 2017, 7:24am UTC](https://discuss.elastic.co/t/python-dsl-syntax/93582/2 "2017-07-21T07:24:52Z")

</div>

Hi,

the problem is that "." is not valid as part of an identifier in Python.

After having [read the docs](http://elasticsearch-dsl.readthedocs.io/en/latest/search_dsl.html?highlight=exclude), I have seen that this is actually short-hand for creating a corresponding instance of `Q`.

I played around a bit with it in the shell:

```auto
> from elasticsearch_dsl import query
> query.Q({"match": { "geoip.country_name": "United States"}})
Match(geoip__country_name='United States')

```

So I _think_, that the following should work:

```auto
.exclude({"match": { "geoip.country_name": "United States"}})

```

Daniel

---

<div class="post-metadata">

**Author:** ![rugenl](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rugenl/32/12887_2.png) [@rugenl](https://discuss.elastic.co/u/rugenl)\
**Post date:** [July 21, 2017, 6:30pm UTC](https://discuss.elastic.co/t/python-dsl-syntax/93582/3 "2017-07-21T18:30:19Z")

</div>

This works:  
.exclude("match", \*\* { "geoip.country\_name": "United States"})

Thanks.

---

<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:** [August 18, 2017, 6:30pm UTC](https://discuss.elastic.co/t/python-dsl-syntax/93582/4 "2017-08-18T18:30:25Z")

</div>

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