Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/unix/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何使用Python在ElasticSearch中创建嵌套索引?_Python_<img Src="//i.stack.imgur.com/RUiNP.png" Height="16" Width="18" Alt="" Class="sponsor Tag Img">elasticsearch - Fatal编程技术网 elasticsearch,Python,elasticsearch" /> elasticsearch,Python,elasticsearch" />

如何使用Python在ElasticSearch中创建嵌套索引?

如何使用Python在ElasticSearch中创建嵌套索引?,python,elasticsearch,Python,elasticsearch,我正在使用中的批量索引添加文档,这些文档包含字典数组形式的嵌套项(address,在本例中): 我创建了一个操作列表,每个文档一个,如下所示: { "_index": "myindex", "_type": "mytype", "_source": the_doc } 然后通过helpers.bulk(es,actions) 我想指定地址为嵌套对象。我在何处使用elasticsearch py向ES指示此信息?请参见: 我用了这个。我创建了一个mytype.py文件: 从el

我正在使用中的批量索引添加文档,这些文档包含字典数组形式的嵌套项(
address
,在本例中):

我创建了一个操作列表,每个文档一个,如下所示:

{
   "_index": "myindex",
   "_type": "mytype",
   "_source": the_doc
}
然后通过
helpers.bulk(es,actions)

我想指定
地址
为嵌套对象。我在何处使用elasticsearch py向ES指示此信息?

请参见:

我用了这个。我创建了一个
mytype.py
文件:

从elasticsearch\u dsl导入DocType,嵌套,字符串
类MyType(DocType):
name=String()
国籍=字符串()
地址=嵌套(
在父项中包含父项=真,
性质={
“位置”:字符串(),
“状态”:字符串(),
“城市”:字符串(),
}
)
然后我将此文件包括在内,并将映射放入elasticsearch中,以允许高亮显示和其他内容:

来自elasticsearch\u dsl导入索引
从mytype导入mytype
myindex=索引(“myindex”)
myindex.doc\u类型(MyType)
myindex.create()

既然您指定了文档类型作为索引的一部分,那么您是如何使用helpers.bulk的?@dter我分两个阶段完成的:首先,我按照描述创建索引本身,然后构建具有适当结构的操作数组(我的操作不使用自定义类,而是使用字典),并通过
helpers.bulk
推送它。自定义类确保操作在索引中正确映射。不确定这是否是正确的方法,但对我来说很有效
{
   "_index": "myindex",
   "_type": "mytype",
   "_source": the_doc
}