Dan*_*edo 4 parent-child elasticsearch
项目和插槽,其中项目槽中文件的父母:我们有两种类型的弹性搜索(ES)的文档.我们使用以下命令定义索引:
curl -XPOST 'localhost:9200/items' -d @itemsdef.json
Run Code Online (Sandbox Code Playgroud)
哪里itemsdef.json有以下定义
{
"mappings" : {
"item" : {
"properties" : {
"id" : {"type" : "long" },
"name" : {
"type" : "string",
"_analyzer" : "textIndexAnalyzer"
},
"location" : {"type" : "geo_point" },
}
}
},
"settings" : {
"analysis" : {
"analyzer" : {
"activityIndexAnalyzer" : {
"alias" : ["activityQueryAnalyzer"],
"type" : "custom",
"tokenizer" : "whitespace",
"filter" : ["trim", "lowercase", "asciifolding", "spanish_stop", "spanish_synonym"]
},
"textIndexAnalyzer" : {
"type" : "custom",
"tokenizer" : "whitespace",
"filter" : ["word_delimiter_impl", "trim", "lowercase", "asciifolding", "spanish_stop", "spanish_synonym"]
},
"textQueryAnalyzer" : {
"type" : "custom",
"tokenizer" : "whitespace",
"filter" : ["trim", "lowercase", "asciifolding", "spanish_stop"]
}
},
"filter" : {
"spanish_stop" : {
"type" : "stop",
"ignore_case" : true,
"enable_position_increments" : true,
"stopwords_path" : "analysis/spanish-stopwords.txt"
},
"spanish_synonym" : {
"type" : "synonym",
"synonyms_path" : "analysis/spanish-synonyms.txt"
},
"word_delimiter_impl" : {
"type" : "word_delimiter",
"generate_word_parts" : true,
"generate_number_parts" : true,
"catenate_words" : true,
"catenate_numbers" : true,
"split_on_case_change" : false
}
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
然后我们使用以下命令添加子文档定义:
curl -XPOST 'localhost:9200/items/slot/_mapping' -d @slotsdef.json
Run Code Online (Sandbox Code Playgroud)
哪里slotsdef.json有以下定义:
{
"slot" : {
"_parent" : {"type" : "item"},
"_routing" : {
"required" : true,
"path" : "parent_id"
},
"properties": {
"id" : { "type" : "long" },
"parent_id" : { "type" : "long" },
"activity" : {
"type" : "string",
"_analyzer" : "activityIndexAnalyzer"
},
"day" : { "type" : "integer" },
"start" : { "type" : "integer" },
"end" : { "type" : "integer" }
}
}
}
Run Code Online (Sandbox Code Playgroud)
最后,我们使用以下命令执行批量索引:
curl -XPOST 'localhost:9200/items/_bulk' --data-binary @testbulk.json
Run Code Online (Sandbox Code Playgroud)
testbulk.json保存以下数据:
{"index":{"_type": "item", "_id":35}}
{"location":[40.4,-3.6],"id":35,"name":"A Name"}
{"index":{"_type":"slot","_id":126,"_parent":35}}
{"id":126,"start":1330,"day":1,"end":1730,"activity":"An Activity","parent_id":35}
Run Code Online (Sandbox Code Playgroud)
我们通过ES Head插件看到定义似乎没问题.我们测试分析仪以检查它们是否已加载并且它们有效.这两个文档都显示在ES Head浏览器视图中.但是如果我们尝试使用API检索子项,ES会回复它不存在:
$ curl -XGET 'localhost:9200/items/slot/126'
{"_index":"items","_type":"slot","_id":"126","exists":false}
Run Code Online (Sandbox Code Playgroud)
当我们导入50个文档,所有父文档可以通过API进行检索,但只有一些子元素的请求获得成功响应.
我的猜测是,它可能是与文档的存储方式跨越碎片和路由......这肯定是我不明白它是如何工作的.
有关如何检索单个子文档的任何线索?ES Head显示它们已存储但HTTP GET到localhost:9200/items/slot/XXX随机响应"exists":false.
imo*_*tov 10
子文档使用父标识进行路由.因此,为了检索子文档,您需要在查询的routing参数中指定父ID:
curl "localhost:9200/items/slot/126?routing=35"
Run Code Online (Sandbox Code Playgroud)
如果父ID不可用,则必须搜索子文档:
curl "localhost:9200/items/slot/_search?q=id:126"
Run Code Online (Sandbox Code Playgroud)
或切换到具有单个分片的索引.
| 归档时间: |
|
| 查看次数: |
3511 次 |
| 最近记录: |