question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Printing out all fields of an entry. without knowing what they are.

See original GitHub issue

Hello again friend! So I’m using the dsl library and i want to know if i can print out an entire entry from the response given. I’m using the following script to search a test instance.

import elasticsearch
from elasticsearch_dsl import Search, Q
from datetime import datetime

es = elasticsearch.Elasticsearch([{u'host': u'himanshu.addteq.com', u'port': b'9200'}])

es.index(index="david", doc_type="test-type", id=42, body={"any": "data", "timestamp": datetime.now()})

s = Search(using=es, index= "_all")
response = s.execute()
for hit in response:
        print hit

and I get this output.

<Result(logstash-2014.12.30/apache/F60rG4hiS42FKL-cx6rnTA): {u'tags': [u'_grokparsefailure'], u'@version': u'1', u'@time...}>
<Result(logstash-2011.08.30/apache/L_CO1AOSTnuvjiBKMl8T_g): {u'ident': u'-', u'referrer': u'"-"', u'@version': u'1', u'@...}>
<Result(logstash-2011.08.30/apache/YEXRqjFjSuOKE6cwLLg0Yw): {u'ident': u'-', u'referrer': u'"-"', u'@version': u'1', u'@...}>
<Result(logstash-2011.08.30/apache/l6QsZNmKQo-s9ZBOftlW4w): {u'ident': u'-', u'referrer': u'"-"', u'@version': u'1', u'@...}>
<Result(logstash-2011.08.30/apache/ONhdAJVhSJC5rfnKAvB78g): {u'ident': u'-', u'referrer': u'"-"', u'@version': u'1', u'@...}> 
...
<Result(logstash-2011.08.30/apache/MeGfj_LTSQWc6D8XugalAg): {u'ident': u'-', u'referrer': u'"http://www.semicomplete.com...}>

I can print the individual fields, like hit.host for example, but printing hit itself does not give me the entire set, I am only given these errors. Thanks again!

Issue Analytics

  • State:closed
  • Created 9 years ago
  • Comments:13 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
davidawadcommented, Dec 30, 2014

I see, is there any way to know if the response were empty?? this will re-create that issue

import elasticsearch
from elasticsearch_dsl import Search, Q
from datetime import datetime

es = elasticsearch.Elasticsearch([{u'host': u'himanshu.addteq.com', u'port': b'9200'}])

s = Search(using=es, index= "_all")

response = s.execute()
for hit in response:
    for field in hit:
        print 'Field %s contains:%r' % (field, hit[field])
0reactions
honzakralcommented, Jan 3, 2015

@ChristopherRabotin just adding that you don’t need to work with the datetimes as text - elasticsearch-py supports datetime objects and will correctly serialize them when sending data to elasticsearch.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Printing the values of an instantiated structure without using ...
Any help would be appreciated. The only information I know it is that all the fields are C++ strings. c++ · string ·...
Read more >
Print each field of CSV on newline without knowing number of ...
I 'm trying to figure out how to do this on a list that's much longer where I wouldn't want to specify every...
Read more >
Has the record been printed? - Allen Browne
It needs more than just a yes/no field to mark the record as printed or not. A better solution is to mark the...
Read more >
Items List won't print out all columns. - SAP Community
Hi. Go to Tools>query > query generator. Select OITM table then you can see all the fields. You can select the field you...
Read more >
Repeat specific rows or columns on every printed page
If a worksheet spans more than one printed page, you can label data by adding row and column headings that will appear on...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found