0

I imagine I'm missing something really obvious here, but somehow I can't quite get it -- I'm using pyes to query an ElasticSearch endpoint pretty straightforwardly, so that I can then access the results by doing something like

print results.hits.hits._source.mets

and get a whole whack of JSON expressed as Python dicts, as expected:

{u'ns0:mets_list': [{u'@xmlns:ns0': u'http://www.loc.gov/METS/', u'@xmlns:ns3': u'http://hul.harvard.edu/ois/xml/ns/fits/fits_output', u'@xmlns:ns2': u'info:lc/xmlns/premis-v2', u'@xmlns:ns4': u'http://www.w3.org/1999/xlink', u'ns0:amdSec_list': [{u'ns0:techMD_list': [{u'ns0:mdWrap_list': [{u'@MDTYPE': u'PREMIS:OBJECT' ...

however, when I try to go a few levels deeper, I run across an issue: there are colons in some of the key names. I've tried every clever solution I can think of to escape these using various combinations of slashes and qutoes, but somehow, I can't quite figure it out, so I keep getting a syntax error on the colons:

print results.hits.hits[0]._source.mets.ns0:mets_list.ns0:fileSec_list

anyone mind pointing out the dumb thing I'm missing here? unfortunately I need to work with a slightly outdated version of pyes for this project so I haven't wanted to lean too heavily on current documentation, and while I have some knowledge of how unicode decoding normally works in Python, it's not revealing the simple solution.

thanks!

serilain
  • 441
  • 4
  • 15

2 Answers2

0
print getattr(results.hits.hits[0]._source.mets,"ns0:mets_list")

might work

Joran Beasley
  • 110,522
  • 12
  • 160
  • 179
  • actually, crap, no -- shouldn't have tested it after hours last night. looks like that still only returns as far down as {mets}, everything below that is ignored. – serilain Jul 22 '14 at 17:11
0

Perhaps the object you want is results.hits.hits[0]._source.mets[u'ns0:mets_list']?

  • that did it. I had to be more explicit about depth on the way down but I was able to get there with print results.hits.hits[0]._source.mets[u'ns0:mets_list'][0][u'ns0:fileSec_list']. – serilain Jul 22 '14 at 19:31