Merge pull request #12150 from martijnvg/aliases/remove_strict_filter_parsing
Don't require fields in alias filters to exist in the mapping
This commit is contained in:
commit
9eb11267f5
|
@ -145,7 +145,6 @@ public class AliasValidator extends AbstractComponent {
|
||||||
QueryParseContext context = indexQueryParserService.getParseContext();
|
QueryParseContext context = indexQueryParserService.getParseContext();
|
||||||
try {
|
try {
|
||||||
context.reset(parser);
|
context.reset(parser);
|
||||||
context.setAllowUnmappedFields(false);
|
|
||||||
context.parseInnerFilter();
|
context.parseInnerFilter();
|
||||||
} finally {
|
} finally {
|
||||||
context.reset(null);
|
context.reset(null);
|
||||||
|
|
|
@ -29,7 +29,6 @@ import org.elasticsearch.action.admin.indices.alias.get.GetAliasesResponse;
|
||||||
import org.elasticsearch.action.admin.indices.create.CreateIndexRequestBuilder;
|
import org.elasticsearch.action.admin.indices.create.CreateIndexRequestBuilder;
|
||||||
import org.elasticsearch.action.index.IndexResponse;
|
import org.elasticsearch.action.index.IndexResponse;
|
||||||
import org.elasticsearch.action.search.SearchResponse;
|
import org.elasticsearch.action.search.SearchResponse;
|
||||||
import org.elasticsearch.action.search.SearchType;
|
|
||||||
import org.elasticsearch.cluster.ClusterState;
|
import org.elasticsearch.cluster.ClusterState;
|
||||||
import org.elasticsearch.cluster.metadata.AliasAction;
|
import org.elasticsearch.cluster.metadata.AliasAction;
|
||||||
import org.elasticsearch.cluster.metadata.AliasMetaData;
|
import org.elasticsearch.cluster.metadata.AliasMetaData;
|
||||||
|
@ -39,7 +38,6 @@ import org.elasticsearch.common.settings.Settings;
|
||||||
import org.elasticsearch.common.unit.TimeValue;
|
import org.elasticsearch.common.unit.TimeValue;
|
||||||
import org.elasticsearch.index.query.QueryBuilder;
|
import org.elasticsearch.index.query.QueryBuilder;
|
||||||
import org.elasticsearch.index.query.QueryBuilders;
|
import org.elasticsearch.index.query.QueryBuilders;
|
||||||
import org.elasticsearch.index.query.QueryParsingException;
|
|
||||||
import org.elasticsearch.rest.action.admin.indices.alias.delete.AliasesMissingException;
|
import org.elasticsearch.rest.action.admin.indices.alias.delete.AliasesMissingException;
|
||||||
import org.elasticsearch.search.SearchHit;
|
import org.elasticsearch.search.SearchHit;
|
||||||
import org.elasticsearch.search.SearchHits;
|
import org.elasticsearch.search.SearchHits;
|
||||||
|
@ -909,29 +907,21 @@ public class IndexAliasesTests extends ElasticsearchIntegrationTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
// Before 2.0 alias filters were parsed at alias creation time, in order
|
||||||
|
// for filters to work correctly ES required that fields mentioned in those
|
||||||
|
// filters exist in the mapping.
|
||||||
|
// From 2.0 and higher alias filters are parsed at request time and therefor
|
||||||
|
// fields mentioned in filters don't need to exist in the mapping.
|
||||||
public void testAddAliasWithFilterNoMapping() throws Exception {
|
public void testAddAliasWithFilterNoMapping() throws Exception {
|
||||||
assertAcked(prepareCreate("test"));
|
assertAcked(prepareCreate("test"));
|
||||||
|
|
||||||
try {
|
|
||||||
client().admin().indices().prepareAliases()
|
client().admin().indices().prepareAliases()
|
||||||
.addAlias("test", "a", QueryBuilders.termQuery("field1", "term"))
|
.addAlias("test", "a", QueryBuilders.termQuery("field1", "term"))
|
||||||
.get();
|
.get();
|
||||||
fail();
|
|
||||||
} catch (IllegalArgumentException e) {
|
|
||||||
assertThat(e.getCause(), instanceOf(QueryParsingException.class));
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
client().admin().indices().prepareAliases()
|
client().admin().indices().prepareAliases()
|
||||||
.addAlias("test", "a", QueryBuilders.rangeQuery("field2").from(0).to(1))
|
.addAlias("test", "a", QueryBuilders.rangeQuery("field2").from(0).to(1))
|
||||||
.get();
|
.get();
|
||||||
fail();
|
|
||||||
} catch (IllegalArgumentException e) {
|
|
||||||
assertThat(e.getCause(), instanceOf(QueryParsingException.class));
|
|
||||||
}
|
|
||||||
|
|
||||||
client().admin().indices().prepareAliases()
|
client().admin().indices().prepareAliases()
|
||||||
.addAlias("test", "a", QueryBuilders.matchAllQuery()) // <-- no fail, b/c no field mentioned
|
.addAlias("test", "a", QueryBuilders.matchAllQuery())
|
||||||
.get();
|
.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -20,9 +20,7 @@ package org.elasticsearch.indices.template;
|
||||||
|
|
||||||
import com.google.common.collect.Lists;
|
import com.google.common.collect.Lists;
|
||||||
import com.google.common.collect.Sets;
|
import com.google.common.collect.Sets;
|
||||||
|
|
||||||
import org.elasticsearch.ElasticsearchParseException;
|
import org.elasticsearch.ElasticsearchParseException;
|
||||||
import org.elasticsearch.ExceptionsHelper;
|
|
||||||
import org.elasticsearch.action.ActionRequestValidationException;
|
import org.elasticsearch.action.ActionRequestValidationException;
|
||||||
import org.elasticsearch.action.admin.indices.alias.Alias;
|
import org.elasticsearch.action.admin.indices.alias.Alias;
|
||||||
import org.elasticsearch.action.admin.indices.alias.get.GetAliasesResponse;
|
import org.elasticsearch.action.admin.indices.alias.get.GetAliasesResponse;
|
||||||
|
@ -33,7 +31,6 @@ import org.elasticsearch.action.bulk.BulkResponse;
|
||||||
import org.elasticsearch.action.index.IndexRequest;
|
import org.elasticsearch.action.index.IndexRequest;
|
||||||
import org.elasticsearch.action.search.SearchResponse;
|
import org.elasticsearch.action.search.SearchResponse;
|
||||||
import org.elasticsearch.cluster.metadata.AliasMetaData;
|
import org.elasticsearch.cluster.metadata.AliasMetaData;
|
||||||
import org.elasticsearch.common.compress.CompressedXContent;
|
|
||||||
import org.elasticsearch.common.settings.Settings;
|
import org.elasticsearch.common.settings.Settings;
|
||||||
import org.elasticsearch.common.xcontent.XContentFactory;
|
import org.elasticsearch.common.xcontent.XContentFactory;
|
||||||
import org.elasticsearch.index.query.QueryBuilders;
|
import org.elasticsearch.index.query.QueryBuilders;
|
||||||
|
@ -44,12 +41,10 @@ import org.elasticsearch.search.SearchHit;
|
||||||
import org.elasticsearch.test.ElasticsearchIntegrationTest;
|
import org.elasticsearch.test.ElasticsearchIntegrationTest;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import static org.elasticsearch.index.query.QueryBuilders.termQuery;
|
|
||||||
import static org.elasticsearch.index.query.QueryBuilders.termQuery;
|
import static org.elasticsearch.index.query.QueryBuilders.termQuery;
|
||||||
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.*;
|
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.*;
|
||||||
import static org.hamcrest.Matchers.*;
|
import static org.hamcrest.Matchers.*;
|
||||||
|
@ -659,17 +654,21 @@ public class SimpleIndexTemplateTests extends ElasticsearchIntegrationTest {
|
||||||
assertThat(response.getItems()[0].getId(), equalTo("test"));
|
assertThat(response.getItems()[0].getId(), equalTo("test"));
|
||||||
assertThat(response.getItems()[0].getVersion(), equalTo(1l));
|
assertThat(response.getItems()[0].getVersion(), equalTo(1l));
|
||||||
|
|
||||||
try {
|
// Before 2.0 alias filters were parsed at alias creation time, in order
|
||||||
|
// for filters to work correctly ES required that fields mentioned in those
|
||||||
|
// filters exist in the mapping.
|
||||||
|
// From 2.0 and higher alias filters are parsed at request time and therefor
|
||||||
|
// fields mentioned in filters don't need to exist in the mapping.
|
||||||
|
// So the aliases defined in the index template for this index will not fail
|
||||||
|
// even though the fields in the alias fields don't exist yet and indexing into
|
||||||
|
// an index that doesn't exist yet will succeed
|
||||||
client().prepareIndex("d1", "test", "test").setSource("{}").get();
|
client().prepareIndex("d1", "test", "test").setSource("{}").get();
|
||||||
fail();
|
|
||||||
} catch (Exception e) {
|
|
||||||
assertThat(ExceptionsHelper.unwrapCause(e), instanceOf(IllegalArgumentException.class));
|
|
||||||
assertThat(e.getMessage(), containsString("failed to parse filter for alias [alias4]"));
|
|
||||||
}
|
|
||||||
response = client().prepareBulk().add(new IndexRequest("d2", "test", "test").source("{}")).get();
|
response = client().prepareBulk().add(new IndexRequest("d2", "test", "test").source("{}")).get();
|
||||||
assertThat(response.hasFailures(), is(true));
|
assertThat(response.hasFailures(), is(false));
|
||||||
assertThat(response.getItems()[0].isFailed(), equalTo(true));
|
assertThat(response.getItems()[0].isFailed(), equalTo(false));
|
||||||
assertThat(response.getItems()[0].getFailureMessage(), containsString("failed to parse filter for alias [alias4]"));
|
assertThat(response.getItems()[0].getId(), equalTo("test"));
|
||||||
|
assertThat(response.getItems()[0].getVersion(), equalTo(1l));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -770,3 +770,8 @@ For the record, official plugins which can use this new simplified form are:
|
||||||
* elasticsearch-lang-javascript
|
* elasticsearch-lang-javascript
|
||||||
* elasticsearch-lang-python
|
* elasticsearch-lang-python
|
||||||
|
|
||||||
|
=== Aliases
|
||||||
|
|
||||||
|
Fields used in alias filters no longer have to exist in the mapping upon alias creation time. Alias filters are now
|
||||||
|
parsed at request time and then the fields in filters are resolved from the mapping, whereas before alias filters were
|
||||||
|
parsed at alias creation time and the parsed form was kept around in memory.
|
Loading…
Reference in New Issue