pyelasticsearch

Format the output of elasticsearch-py

荒凉一梦 提交于 2019-12-01 18:06:40
I'm trying to use the python client for elasticsearch . Here is a minimal example: import logging logging.basicConfig() from elasticsearch import Elasticsearch as ES print "Setup connection..." es=ES(['localhost:8080']) print "Done!" print "Count number of users..." print es.count(index='users') The output is: {u'count': 836780, u'_shards': {u'successful': 5, u'failed': 0, u'total': 5}} I have two questions: How do I get rid of the u' ( u followed by a single quote )? How can I extract the value of count? I guess I could do string manipulation, but that sounds like the wrong way.... Answer: if

python elasticsearch client set mappings during create index

随声附和 提交于 2019-11-29 22:56:39
I can set mappings of index being created in curl command like this: { "mappings":{ "logs_june":{ "_timestamp":{ "enabled":"true" }, "properties":{ "logdate":{ "type":"date", "format":"dd/MM/yyy HH:mm:ss" } } } } } But I need to create that index with elasticsearch client in python and set mappings.. what is the way ? I tried somethings below but not work: self.elastic_con = Elasticsearch([host], verify_certs=True) self.elastic_con.indices.create(index="accesslog", ignore=400) params = "{\"mappings\":{\"logs_june\":{\"_timestamp\": {\"enabled\": \"true\"},\"properties\":{\"logdate\":{\"type\":

python elasticsearch client set mappings during create index

痞子三分冷 提交于 2019-11-28 19:48:43
问题 I can set mappings of index being created in curl command like this: { "mappings":{ "logs_june":{ "_timestamp":{ "enabled":"true" }, "properties":{ "logdate":{ "type":"date", "format":"dd/MM/yyy HH:mm:ss" } } } } } But I need to create that index with elasticsearch client in python and set mappings.. what is the way ? I tried somethings below but not work: self.elastic_con = Elasticsearch([host], verify_certs=True) self.elastic_con.indices.create(index="accesslog", ignore=400) params = "{\