Skip to content

Commit

Permalink
Merge remote-tracking branch 'es/6.x' into ccr-6.x
Browse files Browse the repository at this point in the history
* 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)
  • Loading branch information
martijnvg committed Nov 15, 2017
2 parents 96e0f23 + 5fb9c2a commit 96262bf
Show file tree
Hide file tree
Showing 26 changed files with 1,393 additions and 326 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -114,24 +114,19 @@ public <IFD extends IndexFieldData<?>> IFD getForField(MappedFieldType fieldType
final String fieldName = fieldType.name();
IndexFieldData.Builder builder = fieldType.fielddataBuilder(fullyQualifiedIndexName);

IndexFieldDataCache cache = fieldDataCaches.get(fieldName);
if (cache == null) {
//for perf reason, only synchronize when cache is null
synchronized (this) {
cache = fieldDataCaches.get(fieldName);
//double checked locking to make sure it is thread safe
//especially when other threads calling clear() or clearField()
if (cache == null) {
String cacheType = indexSettings.getValue(INDEX_FIELDDATA_CACHE_KEY);
if (FIELDDATA_CACHE_VALUE_NODE.equals(cacheType)) {
cache = indicesFieldDataCache.buildIndexFieldDataCache(listener, index(), fieldName);
} else if ("none".equals(cacheType)){
cache = new IndexFieldDataCache.None();
} else {
throw new IllegalArgumentException("cache type not supported [" + cacheType + "] for field [" + fieldName + "]");
}
fieldDataCaches.put(fieldName, cache);
IndexFieldDataCache cache;
synchronized (this) {
cache = fieldDataCaches.get(fieldName);
if (cache == null) {
String cacheType = indexSettings.getValue(INDEX_FIELDDATA_CACHE_KEY);
if (FIELDDATA_CACHE_VALUE_NODE.equals(cacheType)) {
cache = indicesFieldDataCache.buildIndexFieldDataCache(listener, index(), fieldName);
} else if ("none".equals(cacheType)){
cache = new IndexFieldDataCache.None();
} else {
throw new IllegalArgumentException("cache type not supported [" + cacheType + "] for field [" + fieldName + "]");
}
fieldDataCaches.put(fieldName, cache);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import org.elasticsearch.common.Nullable;
import org.elasticsearch.common.lucene.Lucene;
import org.elasticsearch.common.lucene.search.Queries;
import org.elasticsearch.common.regex.Regex;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.index.fielddata.IndexFieldData;
Expand Down Expand Up @@ -154,12 +155,8 @@ public Query termsQuery(List values, QueryShardContext context) {
}

private boolean isSameIndex(Object value, String indexName) {
if (value instanceof BytesRef) {
BytesRef indexNameRef = new BytesRef(indexName);
return (indexNameRef.bytesEquals((BytesRef) value));
} else {
return indexName.equals(value.toString());
}
String pattern = value instanceof BytesRef ? pattern = ((BytesRef) value).utf8ToString() : value.toString();
return Regex.simpleMatch(pattern, indexName);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
package org.elasticsearch.index.query;

import org.apache.lucene.index.Term;
import org.apache.lucene.search.MatchAllDocsQuery;
import org.apache.lucene.search.MatchNoDocsQuery;
import org.apache.lucene.search.MultiTermQuery;
import org.apache.lucene.search.Query;
import org.apache.lucene.search.WildcardQuery;
Expand All @@ -31,6 +33,7 @@
import org.elasticsearch.common.lucene.BytesRefs;
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.common.xcontent.XContentParser;
import org.elasticsearch.index.mapper.IndexFieldMapper;
import org.elasticsearch.index.mapper.MappedFieldType;
import org.elasticsearch.index.query.support.QueryParsers;

Expand Down Expand Up @@ -187,6 +190,9 @@ protected Query doToQuery(QueryShardContext context) throws IOException {
term = new Term(fieldName, BytesRefs.toBytesRef(value));
} else {
Query termQuery = fieldType.termQuery(value, context);
if (termQuery instanceof MatchNoDocsQuery || termQuery instanceof MatchAllDocsQuery) {
return termQuery;
}
term = MappedFieldType.extractTerm(termQuery);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
package org.elasticsearch.index.query;

import org.apache.lucene.index.Term;
import org.apache.lucene.search.MatchAllDocsQuery;
import org.apache.lucene.search.MatchNoDocsQuery;
import org.apache.lucene.search.Query;
import org.apache.lucene.search.WildcardQuery;
import org.elasticsearch.common.ParsingException;
Expand Down Expand Up @@ -136,4 +138,20 @@ public void testWithMetaDataField() throws IOException {
assertEquals(expected, query);
}
}

public void testIndexWildcard() throws IOException {
assumeTrue("test runs only when at least a type is registered", getCurrentTypes().length > 0);

QueryShardContext context = createShardContext();
String index = context.getFullyQualifiedIndexName();

Query query = new WildcardQueryBuilder("_index", index).doToQuery(context);
assertThat(query instanceof MatchAllDocsQuery, equalTo(true));

query = new WildcardQueryBuilder("_index", index + "*").doToQuery(context);
assertThat(query instanceof MatchAllDocsQuery, equalTo(true));

query = new WildcardQueryBuilder("_index", "index_" + index + "*").doToQuery(context);
assertThat(query instanceof MatchNoDocsQuery, equalTo(true));
}
}
Loading

0 comments on commit 96262bf

Please sign in to comment.