Elasticsearch 2.x索引映射_id

Elasticsearch 2.x索引映射_id,
Warning: implode(): Invalid arguments passed in /data/phpspider/zhask/webroot/tpl/detail.html on line 45
,,我(高兴地)运行了ElasticSearch1.x一年多。现在是升级到2.1.x的时候了。应关闭节点,然后(逐个)再次打开。看起来很容易。 但后来我遇到了麻烦。主要问题是字段\u uid,我自己创建了该字段,以便从随机的另一个字段(通过散列值)中知道文档的确切位置。这样我就知道只有准确的一个会被退回。在升级过程中,我得到了 MapperParsingException[Field [_uid] is a metadata field and cannot be added inside a do

我(高兴地)运行了ElasticSearch1.x一年多。现在是升级到2.1.x的时候了。应关闭节点,然后(逐个)再次打开。看起来很容易。
但后来我遇到了麻烦。主要问题是字段
\u uid
,我自己创建了该字段,以便从随机的另一个字段(通过散列值)中知道文档的确切位置。这样我就知道只有准确的一个会被退回。在升级过程中,我得到了

MapperParsingException[Field [_uid] is a metadata field and cannot be added inside a document. Use the index API request parameters.]
但是当我尝试将我以前的
\u uid
映射到
\u id
(这也应该足够好)时,我得到了类似的结果

我之所以使用
\u uid
参数,是因为查找时间比termsQuery(或诸如此类)低得多。
如何在每个文档中仍然使用
\u uid
\u id
字段来快速(准确)查找某些准确的文档?请注意,我必须同时调用数千个精确的查询,因此我需要一个类似ID的查询。也可能出现文档的
\u-uid
\u-id
不存在的情况(在这种情况下,像现在一样,我想要一个“类似假”的结果)

注意:从1.x升级到2.x相当大(过滤器消失,名称中没有点,没有对
\u xxx
的默认访问)

更新(无效):
使用以下方法更新
\u uid
\u id
的映射:

final XContentBuilder mappingBuilder = XContentFactory.jsonBuilder().startObject().startObject(type).startObject("_id").field("enabled", "true").field("default", "xxxx").endObject()
            .endObject().endObject();
 CLIENT.admin().indices().prepareCreate(index).addMapping(type, mappingBuilder)
                .setSettings(Settings.settingsBuilder().put("number_of_shards", nShards).put("number_of_replicas", nReplicas)).execute().actionGet();
结果:

MapperParsingException[Failed to parse mapping [XXXX]: _id is not configurable]; nested: MapperParsingException[_id is not configurable];

更新:将名称改为
\u id
,而不是
\u uid
,因为后者是由
\u type
\u id构建的。因此,我需要能够写入
\u id
,因为似乎没有办法设置
\u id
\u id
,我将发布我的解决方案。我将所有具有
\u uid
的文档映射到
uid
(用于内部引用)。我突然想到,您可以设置相关的
id

要批量插入id为
的文档,您可以:

final BulkRequestBuilder builder = client.prepareBulk();
for (final Doc doc : docs) {
    builder.add(client.prepareIndex(index, type, doc.getId()).setSource(doc.toJson()));
}
final BulkResponse bulkResponse = builder.execute().actionGet();
final List<String> uids = getUidsFromSomeMethod(); // ids for documents to get
final MultiGetRequestBuilder builder = CLIENT.prepareMultiGet();
builder.add(index_name, type, uids);
final MultiGetResponse multiResponse = builder.execute().actionGet();
// in this case I simply want to know whether the doc exists
if (only_want_to_know_whether_it_exists){
    for (final MultiGetItemResponse response : multiResponse.getResponses()) {
        final boolean exists = response.getResponse().isExists();
        exist.add(exists);
    }
} else {
    // retrieve the doc as json
    final String string = builder.getSourceAsString();
    // handle JSON
}
注意第三个参数,这个参数可能是
null
(或者是一个两值参数,那么
id
将由ES生成)。
然后通过
id
获取一些文档,您可以:

final BulkRequestBuilder builder = client.prepareBulk();
for (final Doc doc : docs) {
    builder.add(client.prepareIndex(index, type, doc.getId()).setSource(doc.toJson()));
}
final BulkResponse bulkResponse = builder.execute().actionGet();
final List<String> uids = getUidsFromSomeMethod(); // ids for documents to get
final MultiGetRequestBuilder builder = CLIENT.prepareMultiGet();
builder.add(index_name, type, uids);
final MultiGetResponse multiResponse = builder.execute().actionGet();
// in this case I simply want to know whether the doc exists
if (only_want_to_know_whether_it_exists){
    for (final MultiGetItemResponse response : multiResponse.getResponses()) {
        final boolean exists = response.getResponse().isExists();
        exist.add(exists);
    }
} else {
    // retrieve the doc as json
    final String string = builder.getSourceAsString();
    // handle JSON
}
执行-使用
curl
的单个更新是(注意:精确副本):


由于似乎无法设置
\u uid
\u id
我将发布我的解决方案。我将所有具有
\u uid
的文档映射到
uid
(用于内部引用)。我突然想到,您可以设置相关的
id

要批量插入id为
的文档,您可以:

final BulkRequestBuilder builder = client.prepareBulk();
for (final Doc doc : docs) {
    builder.add(client.prepareIndex(index, type, doc.getId()).setSource(doc.toJson()));
}
final BulkResponse bulkResponse = builder.execute().actionGet();
final List<String> uids = getUidsFromSomeMethod(); // ids for documents to get
final MultiGetRequestBuilder builder = CLIENT.prepareMultiGet();
builder.add(index_name, type, uids);
final MultiGetResponse multiResponse = builder.execute().actionGet();
// in this case I simply want to know whether the doc exists
if (only_want_to_know_whether_it_exists){
    for (final MultiGetItemResponse response : multiResponse.getResponses()) {
        final boolean exists = response.getResponse().isExists();
        exist.add(exists);
    }
} else {
    // retrieve the doc as json
    final String string = builder.getSourceAsString();
    // handle JSON
}
注意第三个参数,这个参数可能是
null
(或者是一个两值参数,那么
id
将由ES生成)。
然后通过
id
获取一些文档,您可以:

final BulkRequestBuilder builder = client.prepareBulk();
for (final Doc doc : docs) {
    builder.add(client.prepareIndex(index, type, doc.getId()).setSource(doc.toJson()));
}
final BulkResponse bulkResponse = builder.execute().actionGet();
final List<String> uids = getUidsFromSomeMethod(); // ids for documents to get
final MultiGetRequestBuilder builder = CLIENT.prepareMultiGet();
builder.add(index_name, type, uids);
final MultiGetResponse multiResponse = builder.execute().actionGet();
// in this case I simply want to know whether the doc exists
if (only_want_to_know_whether_it_exists){
    for (final MultiGetItemResponse response : multiResponse.getResponses()) {
        final boolean exists = response.getResponse().isExists();
        exist.add(exists);
    }
} else {
    // retrieve the doc as json
    final String string = builder.getSourceAsString();
    // handle JSON
}
执行-使用
curl
的单个更新是(注意:精确副本):