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 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 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 }))
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 create(self, index, body=None, params=None): if not self.es_client.indices.exists(index=index): logger.info('index "' + index + '": not exists! create now...\nnew mapping:') if body and body.get('mappings') is not None: logger.info(json_util.dumps(body.get('mappings'))) res = self.es_client.indices.create(index=index, body=body, params=params) if res and res['acknowledged']: return 'success' else: raise ElasticsearchException(res)
def bulk(self, body, index=None, doc_type=None, params=None): return Elasticsearch.bulk(self, body=[json_util.dumps(v) for v in body], index=index, doc_type=doc_type, params=params)