Getting field names
See original GitHub issueTL;DR: Is there any “simple” way to get document field names?
Despite ES being schemaless, I believe that many people works with ES respecting schema (which is pretty natural, as we can use object mapping). Personally, I try to verify any data on app side, to avoid implicit mapping, which can lead to troubles in future indexing/migrations.
And as ES have no “constraints” against dynamic mapping and elasticsearch-dsl-py
allows to save docs via DocType(**data
) unpacking, I’ve extended DocType
with
@classmethod
def get_field_names(cls, path=None):
if path is None:
return cls._doc_type.mapping.properties.properties._d_.keys()
else:
getter = attrgetter('.'.join('{}.properties'.format(f) for f in path.split('.') if f))
try:
return getter(cls._doc_type.mapping.properties.properties)._d_.keys()
except AttributeError:
return []
which acts like Django’s get_all_field_names
, but also allows to get field names for Nested
and Object
fields. Is there a simpler way, or such usecase is pretty rare?
Thx.
Issue Analytics
- State:
- Created 8 years ago
- Reactions:1
- Comments:5 (5 by maintainers)
Top Results From Across the Web
Get name of a field - java - Stack Overflow
Show activity on this post. To get field's name, go like that: //use the field object from the example above field. getName(); //...
Read more >MATLAB fieldnames - MathWorks
fields = fieldnames( S ) returns the field names of the structure array S in a cell array. fields = fieldnames( obj ,'-full')...
Read more >How to get column names in Pandas dataframe
Let's discuss how to get column names in Pandas dataframe. First, let's create a simple dataframe with nba.csv file.
Read more >How to get all field names of a table? - ServiceNow Community
Hi, You can go to System Definition -> Dictionary. Here you can type the table name and find all the related field names....
Read more >How do I get all field names for an object in APEX?
system.debug('fieldName->>'+fieldName); // This will give you the api name of the field name. } Thanks. January 9, 2019; · ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
ES isn’t really schema-less, that is a common misconception based on it having a dynamic schema. It does have one. Also it has constraints against dynamic mapping - you can set dynamic to
false
(causing es to ignore unmapped fields) or you can set it tostrict
(causing ES to raise an error on encountering unmapped field) [0]. This made me realize that we don’t have a way to set this in the python dsl (created #146 to track.)With that information I don’t think we need a
get_field_by_name
, orget_fields
. But if you think it would be useful and others agree we can definitely add these method toDocTypeOptions
where I think these should live.Does this make sense?
Thanks
0 - http://www.elastic.co/guide/en/elasticsearch/reference/current/mapping-dynamic-mapping.html
This has been resolved by e1bf242