0
我使用python的elasticsearch客户端来制作可搜索的pdf。一组pdf被称为调查。我想建立一个父母子女关系,其中父母由pdf组成,子女索引将成为组内的文件名。但是,我不断收到错误。我的代码如下:如何使用python Elasticsearch客户端建立父子关系?
import elasticsearch
from elasticsearch import Elasticsearch, RequestsHttpConnection
ES_CLIENT = Elasticsearch(
['http://127.0.0.1:9200/'], #could be 9201,9300,9301
connection_class=RequestsHttpConnection
)
在我command.py
:
settings.py中from elasticsearch import Elasticsearch
from django.conf import settings
self.indices_client = settings.ES_CLIENT
print "create parent"
self.indices_client.index(
# op_type='create',
id='surveys',
doc_type='parent',
body={ "properties": { 'title': {'type': 'string', 'index': 'not_analyzed'}}},
index="surveys"
)
# create child index file_name with parent index surveys
# self.indices_client.create(index=child_index)
print 'create child'
self.indices_client.index(
doc_type='child',
body= upload_models.Survey._meta.es_mapping,
index=child_index,
parent='surveys'
)
print 'post child'
我不断收到此错误:
raise HTTP_EXCEPTIONS.get(status_code, TransportError)(status_code, error_message, additional_info)
elasticsearch.exceptions.RequestError: TransportError(400, u'illegal_argument_exception', u"Can't specify parent if no parent field has been configured")
你是怎么创建你的索引,你的映射是怎样的?你能用'curl -XGET http://127.0.0.1:9200/surveys'获得的回答更新你的问题吗? – Val