# How to GET xml field data from Elasticsearch using Elasticsearch\_DSL?

**URL:** <https://discuss.elastic.co/t/how-to-get-xml-field-data-from-elasticsearch-using-elasticsearch-dsl/154254>\
**Category:** Elasticsearch\
**Created:** [October 26, 2018, 9:05pm UTC](https://discuss.elastic.co/t/how-to-get-xml-field-data-from-elasticsearch-using-elasticsearch-dsl/154254 "2018-10-26T21:05:35Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Samvid\_Kulkarni](https://avatars.discourse-cdn.com/v4/letter/s/439d5e/32.png) [@Samvid\_Kulkarni](https://discuss.elastic.co/u/Samvid_Kulkarni)\
**Post date:** [October 26, 2018, 9:05pm UTC](https://discuss.elastic.co/t/how-to-get-xml-field-data-from-elasticsearch-using-elasticsearch-dsl/154254/1 "2018-10-26T21:05:35Z")

</div>

I have log file which has XML data and I am using XML filter to insert it into Elasticsearch. Now i want to retrieve data from Elasticsearch using Elasticsearch\_DSL python library. I am not able to retrieve it. The JSON response I am getting from Elasticsearch does not contain any data of the XML fields but I can see them in Kibana. is there any way to access it?

[Here is](https://pastebin.com/FthNX67g) the mapping using GET /\_mapping.

below is the code I use to get the data

```
from elasticsearch import Elasticsearch
from elasticsearch_dsl import Search
import json

client = Elasticsearch(['http://localhost:9200'])

s = Search(using=client, index="activedir-*", doc_type = 'doc').filter('range', **{'@timestamp': {'gte': 'now-30m' , 'lt': 'now'}})
response = s.execute()
# print(response.to_dict())

for hit in s.scan():
	print(hit.to_dict())
	print("---------------------------")
	print(hit.parsed_xml.EventID)

```

I am getting this error

```
Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/elasticsearch_dsl/utils.py", line 123, in __getattr__
    return self. __getitem__ (attr_name)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/elasticsearch_dsl/utils.py", line 136, in __getitem__
    return _wrap(self._d_[key])
KeyError: 'parsed_xml'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "Fitness_AD_Eventid_Alert.py", line 16, in <module>
    print(hit.parsed_xml.EventID)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/elasticsearch_dsl/utils.py", line 126, in __getattr__
    '%r object has no attribute %r' % (self. __class__. __name__ , attr_name))
AttributeError: 'Hit' object has no attribute 'parsed_xml'
Miltons-MacBook-Air:user_test samvidkulkarni$
```

---

<div class="post-metadata">

**Author:** ![Samvid\_Kulkarni](https://avatars.discourse-cdn.com/v4/letter/s/439d5e/32.png) [@Samvid\_Kulkarni](https://discuss.elastic.co/u/Samvid_Kulkarni)\
**Post date:** [October 27, 2018, 12:03am UTC](https://discuss.elastic.co/t/how-to-get-xml-field-data-from-elasticsearch-using-elasticsearch-dsl/154254/2 "2018-10-27T00:03:28Z")

</div>

solved the issue. used hit['parsed\_xml']['EventID'] to get the eventid.

---

<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:** [November 24, 2018, 12:04am UTC](https://discuss.elastic.co/t/how-to-get-xml-field-data-from-elasticsearch-using-elasticsearch-dsl/154254/3 "2018-11-24T00:04:12Z")

</div>

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