0

I am doing an elastic client search operation from an elastic datalake which is configured correctly, I double checked the configuration (esDatalake) and I am getting a response from the esDatalake for the first query in my program, so esDatalake works. However when I run another query with a different search_index and search_query later in the code, my code just stops, No Exceptions caught, No errors found, no empty response data found. Why does this happen?

try:
    print("before datalake search")
    widget_data = esDatalake.search(index=search_index, body=widget_query) 
    print("After datalake search")
    if any(error_string in widget_data for error_string in ["error", "Error", "ERROR", "TransportError"]):
        self.logger("Error") 
        raise Exception(f"Elasticsearch error:")
    print(f"widget data is {widget_data}")
    if widget_data: widget_data = widget_data["hits"]["hits"]
    if not widget_data or widget_data == None:
        raise Exception(f"Empty widget data for {widget_id}")
    self.logger.info(f"Data fetched from datalake for {widget_id}")
except Exception as e:
    self.logger.error(f"Could not fetch widget data from {search_index} due to {str(e)}")
    continue # move on to next widget

here "before datalake search" is getting printed but not "After datalake search"

double checked search_index and widget_query, tried the same in kibana dev tools and got result as an empty response message where ["hits"]["hits"] is an empty list []. but with this python code, we are not even getting an empty response message saying ["hits"]["hits"] is an empty list []. why?

2
  • When I run this individually with the same query and index I got the empty response message {'took': 2318, 'timed_out': False, '_shards': {'total': 126, 'successful': 126, 'skipped': 0, 'failed': 0}, 'hits': {'total': {'value': 0, 'relation': 'eq'}, 'max_score': None, 'hits': []}} -- but when I run the same inside my main program I face the above mentioned issue. Commented Feb 11, 2024 at 8:34
  • can you pls share the code where you are establishing the ES connection. As a best practice, you can call ping() as explained in this thread : stackoverflow.com/questions/31208136/… Also recommend moving the None check for widget_data after the search() call, to see if any exceptions are thrown. Also you can check for ['hits']['total']['value'] > 0 before checking the ['hits']['hits'] for results. Commented Feb 11, 2024 at 22:12

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.