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