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.

Calling from_es with returned hits from a Search

See original GitHub issue

My code:

MyDocType.from_es(Search(index='mydoctype').query('match', name=hit_name).execute().hits[0])

I see that the source for from_es uses the variable hit, so I assume it expects to be passed in a hit. This is apparently wrong since I get an attribute error; hit has no attribute copy().

Seems like this is a useful usecase (at least for me), is there a recommended way of doing this sort of thing? Would you be open to a MR to add that if not?

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:6 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
honzakralcommented, Apr 30, 2019

I am wondering why you are doing this instead of just MyDocType.search().query('match', name=hit_name).execute().hits[0] which will already give you an instance of MyDocType?

The from_es method is a low level method to construct the object from the raw dictionary, not the already pre-parsed Hit object. If you want to use it with Hit you will have to refer to the raw response by doing .execute().to_dict()['hits']['hits'][0]

Hope this helps!

0reactions
honzakralcommented, May 27, 2019

The problem is that ContactIndex (or even MyDocType) is looking for index called some-alias but the returning documents are tagged with the name of their actual index so it doesn’t match.

The _matches classmethod needs to be implemented in that case, as per the example (0)

Hope this helps!

0 - https://github.com/elastic/elasticsearch-dsl-py/blob/master/examples/alias_migration.py#L38-L42

Read more comments on GitHub >

github_iconTop Results From Across the Web

Green Day - Good Riddance (Time Of Your Life) [Official Music ...
Watch the official music video for Good Riddance (Time Of Your Life) by Green Day from the album Nimrod. Subscribe to...
Read more >
c# - How can I find the method that called the current method?
Try this: using System.Diagnostics; // Get call stack StackTrace stackTrace = new StackTrace(); // Get calling method name Console.WriteLine(stackTrace.
Read more >
BLAST QuickStart - Comparative Genomics - NCBI Bookshelf
The Basic Local Alignment Search Tool (BLAST) finds regions of local similarity between protein or nucleotide sequences. The program compares nucleotide or ...
Read more >
Top 50 Love Songs of All Time - Billboard
The 50 best love songs of all time on the Billboard charts -- songs with "love" in the title that are the biggest...
Read more >
Chapter 6 Extracting Values from Data Frames | Functions
If RStudio proposes the correct name (and here it does), then all we need to do is hit either tab or return. nrow(sec_class)....
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