======
Sample
======

This test will setup some sample data in our test setup method. After that a
new elasticsearch instance in another sandbox is started for this test. Check
the p01/elasticsearch/test.py file for more info about the sample data and
elasticsearch server setup:

  >>> import json
  >>> from pprint import pprint
  >>> import p01.elasticsearch.testing

Also define a normalizer, see p01/elasticsearch/testing.py for more info:

  >>> statusRENormalizer = p01.elasticsearch.testing.statusRENormalizer

Now let's define a new elasticsearch connection based on our server pool:

  >>> conn = p01.elasticsearch.testing.getTestConnection()

Now we are ready to access the elasticsearch server. Check the status:

  >>> statusRENormalizer.pprint(conn.status())
  {u'_shards': {u'failed': 0, u'successful': 1, u'total': 1},
   u'indices': {u'companies': {u'docs': {u'deleted_docs': 0,
                                         u'max_doc': ...,
                                         u'num_docs': ...},
                               u'flush': {u'total': 0,
                                          u'total_time': u'...',
                                          u'total_time_in_millis': ...},
                               u'index': {u'primary_size': u'...',
                                          u'primary_size_in_bytes': ...,
                                          u'size': u'...',
                                          u'size_in_bytes': ...},
                               u'merges': {u'current': 0,
                                           u'current_docs': 0,
                                           u'current_size': u'0b',
                                           u'current_size_in_bytes': 0,
                                           u'total': 0,
                                           u'total_docs': 0,
                                           u'total_size': u'0b',
                                           u'total_size_in_bytes': 0,
                                           u'total_time': u'...',
                                           u'total_time_in_millis': ...},
                               u'refresh': {u'total': ...,
                                            u'total_time': u'...',
                                            u'total_time_in_millis': ...},
                               u'shards': {u'0': [{u'docs': {u'deleted_docs': 0,
                                                             u'max_doc': ...,
                                                             u'num_docs': ...},
                                                   u'flush': {u'total': 0,
                                                              u'total_time': u'...',
                                                              u'total_time_in_millis': ...},
                                                   u'index': {u'size': u'...',
                                                              u'size_in_bytes': ...},
                                                   u'merges': {u'current': 0,
                                                               u'current_docs': 0,
                                                               u'current_size': u'0b',
                                                               u'current_size_in_bytes': 0,
                                                               u'total': 0,
                                                               u'total_docs': 0,
                                                               u'total_size': u'0b',
                                                               u'total_size_in_bytes': 0,
                                                               u'total_time': u'...',
                                                               u'total_time_in_millis': ...},
                                                   u'refresh': {u'total': ...,
                                                                u'total_time': u'...',
                                                                u'total_time_in_millis': ...},
                                                   u'routing': {u'index': u'companies',
                                                                u'node': u'...',
                                                                u'primary': True,
                                                                u'relocating_node': None,
                                                                u'shard': 0,
                                                                u'state': u'STARTED'},
                                                   u'state': u'STARTED',
                                                   u'translog': {u'id': ...,
                                                                 u'operations': 0}}]},
                               u'translog': {u'operations': 0}}},
   u'ok': True}


companies
---------

As you can see, we can test our sample data mapping:

  >>> pprint(conn.getMapping('companies', 'company'))
  {u'company': {u'properties': {u'__name__': {u'type': u'string'},
                                u'city': {u'type': u'string'},
                                u'number': {u'ignore_malformed': False,
                                            u'type': u'long'},
                                u'street': {u'type': u'string'},
                                u'text': {u'type': u'string'},
                                u'zip': {u'type': u'string'}}}}

And search for our sample data where we added within our sample data generator
in our test setup:

  >>> pprint(conn.search('street').total)
  100
