Skip to content

Commit

Permalink
Added some doc examples with DocType.meta
Browse files Browse the repository at this point in the history
  • Loading branch information
honzakral committed Feb 11, 2015
1 parent c51ac3f commit 977a514
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 4 deletions.
27 changes: 25 additions & 2 deletions docs/persistence.rst
Original file line number Diff line number Diff line change
Expand Up @@ -98,12 +98,35 @@ explicitly:
first = Post(title='My First Blog Post, yay!', published=True)
# assign some field values, can be values or lists of values
first.category = ['everything', 'nothing']
# every document has an id
first.id = 42
# every document has an id in meta
first.meta.id = 47
# save the document into the cluster
first.save()
All the metadata fields (``id``, ``parent``, ``routing``, ``index`` etc) can be
accessed (and set) via a ``meta`` attribute or directly using the underscored
variant:

.. code:: python
post = Post(meta={'id': 42})
# prints 42, same as post._id
print(post.meta.id)
# override default index
post._index = 'my-blog'
.. note::

Having all metadata accesible through ``meta`` means that this name is
reserved and you shouldn't have a field called ``meta`` on your document.
If you, however, need it you can still access the data using the get item
(as opposed to attribute) syntax: ``post['meta']``.

To retrieve an existing document use the ``get`` class method:

.. code:: python
Expand Down
9 changes: 7 additions & 2 deletions docs/search_dsl.rst
Original file line number Diff line number Diff line change
Expand Up @@ -367,14 +367,19 @@ Result

The individual hits is wrapped in a convenience class that allows attribute
access to the keys in the returned dictionary. All the metadata for the results
are accessible via ``_meta`` (without the leading ``_``):
are accessible via ``meta`` (without the leading ``_``):

.. code:: python
response = s.execute()
h = response.hits[0]
print('/%s/%s/%s returned with score %f' % (
h._meta.index, h._meta.doc_type, h._meta.id, h._meta.score))
h.meta.index, h.meta.doc_type, h.meta.id, h.meta.score))
.. note::

If your document has a field called ``meta`` you have to access it using
the get item syntax: ``hit['meta']``.


Aggregations
Expand Down

0 comments on commit 977a514

Please sign in to comment.