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.

lost data when use to_dict() to result

See original GitHub issue
  "_source": {
    "base_info": {
      "profile": null,
      "name": null,
      "headline": null,
      "industry": null,
      "avatar": null,
      "email": "******",
      "location": null

There is the data I have stored in ES and I can get them with RESTful API . The API returns me the full text .
When I get the doc use elasticsearch-dsl-py I also can get the data in search_result<response> like this: {'location': None, 'name': None, 'avatar': None, 'industry': None, 'profile': None, 'headline': None, 'email': '*****'}. But when I try to use result_list = [item.to_dict() for item in search_result] I find the dict it returned is {'email': '******' } and the items which values = None has gone away!

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:12 (6 by maintainers)

github_iconTop GitHub Comments

honzakralcommented, Jan 19, 2018

implemented in 0ee7feeadcc1fdcdb0817e5e0c6816c5f9cff728

honzakralcommented, Jan 19, 2018

I understand your issue. The reason why we decided to ignore those empty fields is:

  • from the dsl point of view there is no difference - accessing tags will return an empty list if not present on the document, accessing body would return None.
  • from the point of view of elasticsearch, there is again no difference
  • finally, sometimes we create those values as a side effect (like accessing tags on an empty document) and we don’t want those to then bloat the document and the index

that said we could totally include a flag to control that behavior for when the data is shared with other systems that don’t have similar properties.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Losing records when converting DataFrame to dictionary
Method 1: reviews = data.set_index('ID')['Reviews'].to_dict(). Method 2: Here we convert reviews to a list for each ID so that we don't lose ......
Read more >
Using dictionaries to store data as key-value pairs
The dictionary stores objects as key-value pairs and can be used to represent complex real-world data.
Read more >
to_dict_of_dicts — NetworkX 2.8.8 documentation
Returns adjacency representation of graph as a dictionary of dictionaries. Parameters: Ggraph. A NetworkX graph. nodelistlist. Use only nodes specified ...
Read more >
pandas.DataFrame.to_dict — pandas 0.23.1 documentation
If you want a collections.defaultdict, you must pass it initialized. New in version 0.21.0. Returns: result : collections.Mapping like {column -> {index ...
Read more >
Excel VBA Dictionary - A Complete Guide
Storing Multiple Values in One Key. Take a look at the sample data below. We want to store the Amount and Items for...
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 Post

No results found

github_iconTop Related Hashnode Post

No results found