Elasticsearch Percolator with python api
Question: Hi I am trying to do a percolator index using "elasticsearch.py" api. But I am
not even getting any results.

The API documentation seems to have 3 or 4 functions related to percolation.

I have checked the following possibilities. can anyone be of some help , so
that I can solve it.

    
    
    es = Elasticsearch()
    query = {'query': {'term': {'message': 'bonsai tree'}}}
    es.create(index='test', doc_type='message', percolate=query, id='kuku2', body = {"message":"bonsai tree"})
    doc = {'doc': {'message': 'I am a bonsai tree'}}
    k = es.percolate(index='test', doc_type='type1', body=doc)
    print k
    

###### Result #####

    
    
     u'matches': [], u'total': 0, u'took': 0, u'_shards': {u'successful': 1, u'failed': 0, u'total': 1}}
    

I hope "es.percolate" is used for searching. "es.create" allows us to register
documents as percolate index. But it is not so perfectly mentioned in the
documentation. ".percolate" have also used in the place of index. Please help.


Answer: The following piece of text works for me (on ES 1.4.4). The key point seems to
be the use of `doc_type='.percolator'` in `es.create`.

    
    
        from elasticsearch import Elasticsearch
        from elasticsearch.client.indices import IndicesClient
    
        es = Elasticsearch()
        ies = IndicesClient(es)
    
        mapping = {
          "mappings": {
            "my-type": {
              "properties": {
                "content": {
                  "type": "string"
                }
              }
            }
          }
        }
        ies.create(index='test_index', body=mapping)
    
        query = {
            "query": {
                "match": {
                    "content": "python"
                }
            }
        }
        es.create(index='test_index', doc_type='.percolator', body=query, id='python')
    
        doc1 = {'doc': {'content': 'this is something about python'}}
        res = es.percolate("test_index", doc_type="my-type", body = doc1)
        print res
    
        # result:
        # {u'matches': [{u'_id': u'python', u'_index': u'test_index'}], u'total': 1, u'took': 3, u'_shards': {u'successful': 5, u'failed': 0, u'total': 5}}
    
    
        doc2 = {'doc': {'content': 'this is another piece of text'}}
        res = es.percolate("test_index", doc_type="my-type", body = doc2)
        print res
        # result:
        # {u'matches': [], u'total': 0, u'took': 2, u'_shards': {u'successful': 5, u'failed': 0, u'total': 5}}
    

