在弹性搜索中使用现有的字段作为id [英] Use existing field as id in elasticsearch
问题描述
今天刚开始使用elasticSearch。我想知道是否可以设置某种全局参数来使用文档中的某个字段作为ID?
Just started using elasticSearch today. I was wondering if it would be possible to set in some kind of global parameter to use a certain field within a document as the ID always?
我的JSON文档将始终具有它是自己唯一的ID
My JSON documents will always have it's own unique ID
{
"Record ID": "a06b0000004SWbdAAG",
"System Modstamp": "01/31/2013T07:46:02.000Z",
"body": "Test Body"
}
这里我想使用记录ID作为ID字段。
Here I would like to use Record ID as the ID field.
注意
推荐答案
要使用路径设置,请参阅这里的文档:
You want to use the path setting, see the docs here:
http://www.elasticsearch.org/guide/reference/mapping/id-field/
具体而言应该在你的映射中工作:
specifically something like this should work in your mapping:
{
"your_mapping" : {
"_id" : {
"path" : "Record ID"
}
}
}
我从来没有尝试过将变量名称分解。如果你遇到懦弱,你可能想要骆驼或下划线。
I've never tried having variable names split up though. You might want to camelcase or underscore them if you run into wierdness.
这篇关于在弹性搜索中使用现有的字段作为id的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!