diff options
author | Adrien Grand <jpountz@gmail.com> | 2017-05-09 16:33:52 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-05-09 16:33:52 +0200 |
commit | a72eaa8e0f5c0f305c507c5fcd918fed7c1bf6bf (patch) | |
tree | cb1404480d25d1501d02f4337971b8234ddfaa23 /core/src/main/java/org/elasticsearch/index/query/IdsQueryBuilder.java | |
parent | f222748506dee3f50f99551b33b049e87c6cd425 (diff) |
Identify documents by their `_id`. (#24460)
Now that indices have a single type by default, we can move to the next step
and identify documents using their `_id` rather than the `_uid`.
One notable change in this commit is that I made deletions implicitly create
types. This helps with the live version map in the case that documents are
deleted before the first type is introduced. Otherwise there would be no way
to differenciate `DELETE index/foo/1` followed by `PUT index/foo/1` from
`DELETE index/bar/1` followed by `PUT index/foo/1`, even though those are
different if versioning is involved.
Diffstat (limited to 'core/src/main/java/org/elasticsearch/index/query/IdsQueryBuilder.java')
-rw-r--r-- | core/src/main/java/org/elasticsearch/index/query/IdsQueryBuilder.java | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/core/src/main/java/org/elasticsearch/index/query/IdsQueryBuilder.java b/core/src/main/java/org/elasticsearch/index/query/IdsQueryBuilder.java index 5857ef9abf..1b756062dc 100644 --- a/core/src/main/java/org/elasticsearch/index/query/IdsQueryBuilder.java +++ b/core/src/main/java/org/elasticsearch/index/query/IdsQueryBuilder.java @@ -19,8 +19,8 @@ package org.elasticsearch.index.query; +import org.apache.lucene.search.MatchNoDocsQuery; import org.apache.lucene.search.Query; -import org.apache.lucene.search.TermInSetQuery; import org.elasticsearch.cluster.metadata.MetaData; import org.elasticsearch.common.ParseField; import org.elasticsearch.common.ParsingException; @@ -30,6 +30,7 @@ import org.elasticsearch.common.io.stream.StreamOutput; import org.elasticsearch.common.lucene.search.Queries; import org.elasticsearch.common.xcontent.ObjectParser; import org.elasticsearch.common.xcontent.XContentBuilder; +import org.elasticsearch.index.mapper.MappedFieldType; import org.elasticsearch.index.mapper.Uid; import org.elasticsearch.index.mapper.UidFieldMapper; @@ -162,6 +163,10 @@ public class IdsQueryBuilder extends AbstractQueryBuilder<IdsQueryBuilder> { @Override protected Query doToQuery(QueryShardContext context) throws IOException { Query query; + MappedFieldType uidField = context.fieldMapper(UidFieldMapper.NAME); + if (uidField == null) { + return new MatchNoDocsQuery("No mappings"); + } if (this.ids.isEmpty()) { query = Queries.newMatchNoDocsQuery("Missing ids in \"" + this.getName() + "\" query."); } else { @@ -175,7 +180,7 @@ public class IdsQueryBuilder extends AbstractQueryBuilder<IdsQueryBuilder> { Collections.addAll(typesForQuery, types); } - query = new TermInSetQuery(UidFieldMapper.NAME, Uid.createUidsForTypesAndIds(typesForQuery, ids)); + query = uidField.termsQuery(Arrays.asList(Uid.createUidsForTypesAndIds(typesForQuery, ids)), context); } return query; } |