【发布时间】:2016-06-19 16:11:38
【问题描述】:
我正在使用 python 的 elasticsearch 客户端来制作可搜索的 pdf。一组pdf称为调查。我想建立一个父子关系,其中父级由 pdf 组组成,子索引将是组内的文件名。但是,我不断收到错误。我的代码如下:
在 settings.py 中:
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 中:
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的回复更新你的问题吗?
标签: python django elasticsearch parent-child relationships