Skip to content

Commit 96262bf

Browse files
committed
Merge remote-tracking branch 'es/6.x' into ccr-6.x
* es/6.x: Updated 6.0.0 release notes to include all changes from alpha, beta, RC wildcard query on _index (#27334) REST spec: Validate that api name matches file name that contains it (#27366) Revert "Reduce synchronization on field data cache" Create new handlers for every new request in GoogleCloudStorageService (#27339) Rest test fixes (#27354)
2 parents 96e0f23 + 5fb9c2a commit 96262bf

File tree

26 files changed

+1393
-326
lines changed

26 files changed

+1393
-326
lines changed

core/src/main/java/org/elasticsearch/index/fielddata/IndexFieldDataService.java

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -114,24 +114,19 @@ public <IFD extends IndexFieldData<?>> IFD getForField(MappedFieldType fieldType
114114
final String fieldName = fieldType.name();
115115
IndexFieldData.Builder builder = fieldType.fielddataBuilder(fullyQualifiedIndexName);
116116

117-
IndexFieldDataCache cache = fieldDataCaches.get(fieldName);
118-
if (cache == null) {
119-
//for perf reason, only synchronize when cache is null
120-
synchronized (this) {
121-
cache = fieldDataCaches.get(fieldName);
122-
//double checked locking to make sure it is thread safe
123-
//especially when other threads calling clear() or clearField()
124-
if (cache == null) {
125-
String cacheType = indexSettings.getValue(INDEX_FIELDDATA_CACHE_KEY);
126-
if (FIELDDATA_CACHE_VALUE_NODE.equals(cacheType)) {
127-
cache = indicesFieldDataCache.buildIndexFieldDataCache(listener, index(), fieldName);
128-
} else if ("none".equals(cacheType)){
129-
cache = new IndexFieldDataCache.None();
130-
} else {
131-
throw new IllegalArgumentException("cache type not supported [" + cacheType + "] for field [" + fieldName + "]");
132-
}
133-
fieldDataCaches.put(fieldName, cache);
117+
IndexFieldDataCache cache;
118+
synchronized (this) {
119+
cache = fieldDataCaches.get(fieldName);
120+
if (cache == null) {
121+
String cacheType = indexSettings.getValue(INDEX_FIELDDATA_CACHE_KEY);
122+
if (FIELDDATA_CACHE_VALUE_NODE.equals(cacheType)) {
123+
cache = indicesFieldDataCache.buildIndexFieldDataCache(listener, index(), fieldName);
124+
} else if ("none".equals(cacheType)){
125+
cache = new IndexFieldDataCache.None();
126+
} else {
127+
throw new IllegalArgumentException("cache type not supported [" + cacheType + "] for field [" + fieldName + "]");
134128
}
129+
fieldDataCaches.put(fieldName, cache);
135130
}
136131
}
137132

core/src/main/java/org/elasticsearch/index/mapper/IndexFieldMapper.java

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import org.elasticsearch.common.Nullable;
2929
import org.elasticsearch.common.lucene.Lucene;
3030
import org.elasticsearch.common.lucene.search.Queries;
31+
import org.elasticsearch.common.regex.Regex;
3132
import org.elasticsearch.common.settings.Settings;
3233
import org.elasticsearch.common.xcontent.XContentBuilder;
3334
import org.elasticsearch.index.fielddata.IndexFieldData;
@@ -154,12 +155,8 @@ public Query termsQuery(List values, QueryShardContext context) {
154155
}
155156

156157
private boolean isSameIndex(Object value, String indexName) {
157-
if (value instanceof BytesRef) {
158-
BytesRef indexNameRef = new BytesRef(indexName);
159-
return (indexNameRef.bytesEquals((BytesRef) value));
160-
} else {
161-
return indexName.equals(value.toString());
162-
}
158+
String pattern = value instanceof BytesRef ? pattern = ((BytesRef) value).utf8ToString() : value.toString();
159+
return Regex.simpleMatch(pattern, indexName);
163160
}
164161

165162
@Override

core/src/main/java/org/elasticsearch/index/query/WildcardQueryBuilder.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
package org.elasticsearch.index.query;
2121

2222
import org.apache.lucene.index.Term;
23+
import org.apache.lucene.search.MatchAllDocsQuery;
24+
import org.apache.lucene.search.MatchNoDocsQuery;
2325
import org.apache.lucene.search.MultiTermQuery;
2426
import org.apache.lucene.search.Query;
2527
import org.apache.lucene.search.WildcardQuery;
@@ -31,6 +33,7 @@
3133
import org.elasticsearch.common.lucene.BytesRefs;
3234
import org.elasticsearch.common.xcontent.XContentBuilder;
3335
import org.elasticsearch.common.xcontent.XContentParser;
36+
import org.elasticsearch.index.mapper.IndexFieldMapper;
3437
import org.elasticsearch.index.mapper.MappedFieldType;
3538
import org.elasticsearch.index.query.support.QueryParsers;
3639

@@ -187,6 +190,9 @@ protected Query doToQuery(QueryShardContext context) throws IOException {
187190
term = new Term(fieldName, BytesRefs.toBytesRef(value));
188191
} else {
189192
Query termQuery = fieldType.termQuery(value, context);
193+
if (termQuery instanceof MatchNoDocsQuery || termQuery instanceof MatchAllDocsQuery) {
194+
return termQuery;
195+
}
190196
term = MappedFieldType.extractTerm(termQuery);
191197
}
192198

core/src/test/java/org/elasticsearch/index/query/WildcardQueryBuilderTests.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
package org.elasticsearch.index.query;
2121

2222
import org.apache.lucene.index.Term;
23+
import org.apache.lucene.search.MatchAllDocsQuery;
24+
import org.apache.lucene.search.MatchNoDocsQuery;
2325
import org.apache.lucene.search.Query;
2426
import org.apache.lucene.search.WildcardQuery;
2527
import org.elasticsearch.common.ParsingException;
@@ -136,4 +138,20 @@ public void testWithMetaDataField() throws IOException {
136138
assertEquals(expected, query);
137139
}
138140
}
141+
142+
public void testIndexWildcard() throws IOException {
143+
assumeTrue("test runs only when at least a type is registered", getCurrentTypes().length > 0);
144+
145+
QueryShardContext context = createShardContext();
146+
String index = context.getFullyQualifiedIndexName();
147+
148+
Query query = new WildcardQueryBuilder("_index", index).doToQuery(context);
149+
assertThat(query instanceof MatchAllDocsQuery, equalTo(true));
150+
151+
query = new WildcardQueryBuilder("_index", index + "*").doToQuery(context);
152+
assertThat(query instanceof MatchAllDocsQuery, equalTo(true));
153+
154+
query = new WildcardQueryBuilder("_index", "index_" + index + "*").doToQuery(context);
155+
assertThat(query instanceof MatchNoDocsQuery, equalTo(true));
156+
}
139157
}

0 commit comments

Comments
 (0)