def index(self, index, doc_type, body, id=None, params=None): return Elasticsearch.index(self, index=index, doc_type=doc_type, body=json_util.dumps(body), id=id, params=params)
def update(self, index, doc_type, id, body=None, params=None): return Elasticsearch.update(self, index=index, doc_type=doc_type, id=id, body=json_util.dumps(body), params=params)
def bulk(self, body, index=None, doc_type=None, params=None): self.producer.send(topic=self.topic, value=json_util.dumps({'op': 'bulk', 'index': index, 'doc_type': doc_type, 'body': body, 'params': params })) # 兼容Elasticsearch原生sdk返回结果 return {'errors': None, 'items': []}
def bulk(self, body, index=None, doc_type=None, params=None): for i, v in enumerate(body): body[i] = json_util.dumps(v) return Elasticsearch.bulk(self, body=body, index=index, doc_type=doc_type, params=params)
def delete(self, index, doc_type, id, params=None): redis_client.rpush( self.redis_key, json_util.dumps({ 'op': 'delete', 'index': index, 'doc_type': doc_type, 'id': id, 'params': params }))
def delete_by_query(self, index, body, doc_type=None, params=None): redis_client.rpush( self.redis_key, json_util.dumps({ 'op': 'delete_by_query', 'index': index, 'doc_type': doc_type, 'body': body, 'params': params }))
def update(self, index, doc_type, id, body=None, params=None): redis_client.rpush( self.redis_key, json_util.dumps({ 'op': 'update', 'index': index, 'doc_type': doc_type, 'body': body, 'id': id, 'params': params }))
def bulk(self, body, index=None, doc_type=None, params=None): redis_client.rpush( self.redis_key, json_util.dumps({ 'op': 'bulk', 'index': index, 'doc_type': doc_type, 'body': body, 'params': params })) # 兼容Elasticsearch原生sdk返回结果 return {'errors': None, 'items': []}
def create(index, mappings=None, settings=None): if not es_client.indices.exists(index=index): logger.info('index "' + index + '": not exists! create now...\nnew mapping:') logger.info(json_util.dumps(mappings)) res = es_client.indices.create(index=index, body={ 'mappings': mappings, 'settings': settings }) if res and res['acknowledged']: return 'success' else: raise ElasticsearchException(res)
def test_json_util_dumps(self): r = json_util.dumps({'test': True}) print(r)
}, sort=[('_id', 1)], skip=0, limit=10, pop_fields={ 'user': { 'from': 'users', 'local_field': 'support', 'foreign_field': '_id', 'projection': { '_id': 1, 'phone': 1 }, 'pop_fields': { 'city': { 'from': 'cities', 'local_field': 'cityId', 'foreign_field': '_id', 'projection': { '_id': 1, 'name': 1 }, 'as': 'city' } } } }) for m in merchants: print(json_util.dumps(m))
def delete_by_query(self, index, body, doc_type=None, params=None): self.producer.send(topic=self.topic, value=json_util.dumps({'op': 'delete_by_query', 'index': index, 'doc_type': doc_type, 'body': body, 'params': params }))
def delete(self, index, doc_type, id, params=None): self.producer.send(topic=self.topic, value=json_util.dumps( {'op': 'delete', 'index': index, 'doc_type': doc_type, 'id': id, 'params': params}))
def update(self, index, doc_type, id, body=None, params=None): self.producer.send(topic=self.topic, value=json_util.dumps({'op': 'update', 'index': index, 'doc_type': doc_type, 'body': body, 'id': id, 'params': params}))