This is a sibling of elastic/elasticsearch#29224.

Original commit: elastic/x-pack-elasticsearch@1c16d86f78
This commit is contained in:
Adrien Grand 2018-04-11 08:43:52 +02:00 committed by GitHub
parent 20dbd75623
commit bd834b7357
5 changed files with 11 additions and 108 deletions

View File

@ -48,7 +48,6 @@ import org.elasticsearch.index.IndexSettings;
import org.elasticsearch.index.cache.bitset.BitsetFilterCache; import org.elasticsearch.index.cache.bitset.BitsetFilterCache;
import org.elasticsearch.index.mapper.FieldNamesFieldMapper; import org.elasticsearch.index.mapper.FieldNamesFieldMapper;
import org.elasticsearch.index.mapper.MapperService; import org.elasticsearch.index.mapper.MapperService;
import org.elasticsearch.index.mapper.ParentFieldMapper;
import org.elasticsearch.index.mapper.SeqNoFieldMapper; import org.elasticsearch.index.mapper.SeqNoFieldMapper;
import org.elasticsearch.index.mapper.SourceFieldMapper; import org.elasticsearch.index.mapper.SourceFieldMapper;
import org.elasticsearch.index.query.BoolQueryBuilder; import org.elasticsearch.index.query.BoolQueryBuilder;
@ -171,7 +170,6 @@ public class SecurityIndexSearcherWrapperUnitTests extends ESTestCase {
assertThat(result.getFilter().run("_type"), is(true)); assertThat(result.getFilter().run("_type"), is(true));
assertThat(result.getFilter().run("_source"), is(true)); assertThat(result.getFilter().run("_source"), is(true));
assertThat(result.getFilter().run("_routing"), is(true)); assertThat(result.getFilter().run("_routing"), is(true));
assertThat(result.getFilter().run("_parent"), is(true));
assertThat(result.getFilter().run("_timestamp"), is(true)); assertThat(result.getFilter().run("_timestamp"), is(true));
assertThat(result.getFilter().run("_ttl"), is(true)); assertThat(result.getFilter().run("_ttl"), is(true));
assertThat(result.getFilter().run("_size"), is(true)); assertThat(result.getFilter().run("_size"), is(true));
@ -216,13 +214,6 @@ public class SecurityIndexSearcherWrapperUnitTests extends ESTestCase {
assertResolved(new FieldPermissions(fieldPermissionDef(new String[] {"foo.*"}, null)), expected, "foo", "bar"); assertResolved(new FieldPermissions(fieldPermissionDef(new String[] {"foo.*"}, null)), expected, "foo", "bar");
} }
public void testParentChild() throws Exception {
Set<String> expected = new HashSet<>(META_FIELDS);
expected.add(ParentFieldMapper.joinField("parent1"));
expected.add("foo");
assertResolved(new FieldPermissions(fieldPermissionDef(new String[] {"foo"}, null)), expected, "bar");
}
public void testDelegateSimilarity() throws Exception { public void testDelegateSimilarity() throws Exception {
IndexSettings settings = IndexSettingsModule.newIndexSettings("_index", Settings.EMPTY); IndexSettings settings = IndexSettingsModule.newIndexSettings("_index", Settings.EMPTY);
BitsetFilterCache bitsetFilterCache = new BitsetFilterCache(settings, new BitsetFilterCache.Listener() { BitsetFilterCache bitsetFilterCache = new BitsetFilterCache(settings, new BitsetFilterCache.Listener() {

View File

@ -134,7 +134,7 @@ public class DocumentAndFieldLevelSecurityTests extends SecurityIntegTestCase {
response = client().filterWithHeader(Collections.singletonMap(BASIC_AUTH_HEADER, basicAuthHeaderValue("user4", USERS_PASSWD))) response = client().filterWithHeader(Collections.singletonMap(BASIC_AUTH_HEADER, basicAuthHeaderValue("user4", USERS_PASSWD)))
.prepareSearch("test") .prepareSearch("test")
.addSort("_uid", SortOrder.ASC) .addSort("_id", SortOrder.ASC)
.get(); .get();
assertHitCount(response, 2); assertHitCount(response, 2);
assertSearchHits(response, "1", "2"); assertSearchHits(response, "1", "2");
@ -214,7 +214,7 @@ public class DocumentAndFieldLevelSecurityTests extends SecurityIntegTestCase {
response = client().filterWithHeader( response = client().filterWithHeader(
Collections.singletonMap(BASIC_AUTH_HEADER, basicAuthHeaderValue("user4", USERS_PASSWD))) Collections.singletonMap(BASIC_AUTH_HEADER, basicAuthHeaderValue("user4", USERS_PASSWD)))
.prepareSearch("test") .prepareSearch("test")
.addSort("_uid", SortOrder.ASC) .addSort("_id", SortOrder.ASC)
.get(); .get();
assertHitCount(response, 2); assertHitCount(response, 2);
assertThat(response.getHits().getAt(0).getId(), equalTo("1")); assertThat(response.getHits().getAt(0).getId(), equalTo("1"));

View File

@ -600,80 +600,7 @@ public class DocumentLevelSecurityTests extends SecurityIntegTestCase {
assertThat(termsAgg.getBuckets().size(), equalTo(1)); assertThat(termsAgg.getBuckets().size(), equalTo(1));
} }
public void testChildrenAggregation() throws Exception { public void testParentChild() throws Exception {
assertAcked(client().admin().indices().prepareCreate("test")
.setSettings(Settings.builder().put("index.version.created", Version.V_5_6_0.id))
.addMapping("type1", "field1", "type=text", "field2", "type=text")
.addMapping("type2", "_parent", "type=type1", "field3", "type=text,fielddata=true")
);
client().prepareIndex("test", "type1", "1").setSource("field1", "value1")
.setRefreshPolicy(IMMEDIATE)
.get();
client().prepareIndex("test", "type2", "2").setSource("field3", "value3")
.setParent("1")
.setRefreshPolicy(IMMEDIATE)
.get();
SearchResponse response = client().prepareSearch("test")
.setTypes("type1")
.addAggregation(JoinAggregationBuilders.children("children", "type2")
.subAggregation(AggregationBuilders.terms("field3").field("field3")))
.get();
assertHitCount(response, 1);
assertSearchHits(response, "1");
Children children = response.getAggregations().get("children");
assertThat(children.getDocCount(), equalTo(1L));
Terms termsAgg = children.getAggregations().get("field3");
assertThat(termsAgg.getBuckets().get(0).getKeyAsString(), equalTo("value3"));
assertThat(termsAgg.getBuckets().get(0).getDocCount(), equalTo(1L));
response = client().filterWithHeader(Collections.singletonMap(BASIC_AUTH_HEADER, basicAuthHeaderValue("user1", USERS_PASSWD)))
.prepareSearch("test")
.setTypes("type1")
.addAggregation(JoinAggregationBuilders.children("children", "type2")
.subAggregation(AggregationBuilders.terms("field3").field("field3")))
.get();
assertHitCount(response, 1);
assertSearchHits(response, "1");
children = response.getAggregations().get("children");
assertThat(children.getDocCount(), equalTo(0L));
termsAgg = children.getAggregations().get("field3");
assertThat(termsAgg.getBuckets().size(), equalTo(0));
response = client().filterWithHeader(Collections.singletonMap(BASIC_AUTH_HEADER, basicAuthHeaderValue("user3", USERS_PASSWD)))
.prepareSearch("test")
.setTypes("type1")
.addAggregation(JoinAggregationBuilders.children("children", "type2")
.subAggregation(AggregationBuilders.terms("field3").field("field3")))
.get();
assertHitCount(response, 1);
assertSearchHits(response, "1");
children = response.getAggregations().get("children");
assertThat(children.getDocCount(), equalTo(0L));
termsAgg = children.getAggregations().get("field3");
assertThat(termsAgg.getBuckets().size(), equalTo(0));
}
public void testParentChild_parentField() {
assertAcked(prepareCreate("test")
.setSettings(Settings.builder().put("index.version.created", Version.V_5_6_0.id))
.addMapping("parent")
.addMapping("child", "_parent", "type=parent", "field1", "type=text", "field2", "type=text", "field3", "type=text"));
ensureGreen();
// index simple data
client().prepareIndex("test", "parent", "p1").setSource("field1", "value1").get();
client().prepareIndex("test", "child", "c1").setSource("field2", "value2").setParent("p1").get();
client().prepareIndex("test", "child", "c2").setSource("field2", "value2").setParent("p1").get();
client().prepareIndex("test", "child", "c3").setSource("field3", "value3").setParent("p1").get();
refresh();
verifyParentChild();
}
public void testParentChild_joinField() throws Exception {
XContentBuilder mapping = jsonBuilder().startObject() XContentBuilder mapping = jsonBuilder().startObject()
.startObject("properties") .startObject("properties")
.startObject("join_field") .startObject("join_field")
@ -725,7 +652,7 @@ public class DocumentLevelSecurityTests extends SecurityIntegTestCase {
searchResponse = client().prepareSearch("test") searchResponse = client().prepareSearch("test")
.setQuery(hasParentQuery("parent", matchAllQuery(), false)) .setQuery(hasParentQuery("parent", matchAllQuery(), false))
.addSort("_uid", SortOrder.ASC) .addSort("_id", SortOrder.ASC)
.get(); .get();
assertHitCount(searchResponse, 3L); assertHitCount(searchResponse, 3L);
assertThat(searchResponse.getHits().getAt(0).getId(), equalTo("c1")); assertThat(searchResponse.getHits().getAt(0).getId(), equalTo("c1"));

View File

@ -181,7 +181,7 @@ public class FieldLevelSecurityRandomTests extends SecurityIntegTestCase {
SearchResponse actual = client() SearchResponse actual = client()
.filterWithHeader(Collections.singletonMap(BASIC_AUTH_HEADER, basicAuthHeaderValue("user2", USERS_PASSWD))) .filterWithHeader(Collections.singletonMap(BASIC_AUTH_HEADER, basicAuthHeaderValue("user2", USERS_PASSWD)))
.prepareSearch("test") .prepareSearch("test")
.addSort("_uid", SortOrder.ASC) .addSort("_id", SortOrder.ASC)
.setQuery(QueryBuilders.boolQuery() .setQuery(QueryBuilders.boolQuery()
.should(QueryBuilders.termQuery("field1", "value")) .should(QueryBuilders.termQuery("field1", "value"))
.should(QueryBuilders.termQuery("field2", "value")) .should(QueryBuilders.termQuery("field2", "value"))
@ -189,7 +189,7 @@ public class FieldLevelSecurityRandomTests extends SecurityIntegTestCase {
) )
.get(); .get();
SearchResponse expected = client().prepareSearch("test") SearchResponse expected = client().prepareSearch("test")
.addSort("_uid", SortOrder.ASC) .addSort("_id", SortOrder.ASC)
.setQuery(QueryBuilders.boolQuery() .setQuery(QueryBuilders.boolQuery()
.should(QueryBuilders.termQuery("field1", "value")) .should(QueryBuilders.termQuery("field1", "value"))
) )
@ -202,7 +202,7 @@ public class FieldLevelSecurityRandomTests extends SecurityIntegTestCase {
actual = client().filterWithHeader(Collections.singletonMap(BASIC_AUTH_HEADER, basicAuthHeaderValue("user3", USERS_PASSWD))) actual = client().filterWithHeader(Collections.singletonMap(BASIC_AUTH_HEADER, basicAuthHeaderValue("user3", USERS_PASSWD)))
.prepareSearch("test") .prepareSearch("test")
.addSort("_uid", SortOrder.ASC) .addSort("_id", SortOrder.ASC)
.setQuery(QueryBuilders.boolQuery() .setQuery(QueryBuilders.boolQuery()
.should(QueryBuilders.termQuery("field1", "value")) .should(QueryBuilders.termQuery("field1", "value"))
.should(QueryBuilders.termQuery("field2", "value")) .should(QueryBuilders.termQuery("field2", "value"))
@ -210,7 +210,7 @@ public class FieldLevelSecurityRandomTests extends SecurityIntegTestCase {
) )
.get(); .get();
expected = client().prepareSearch("test") expected = client().prepareSearch("test")
.addSort("_uid", SortOrder.ASC) .addSort("_id", SortOrder.ASC)
.setQuery(QueryBuilders.boolQuery() .setQuery(QueryBuilders.boolQuery()
.should(QueryBuilders.termQuery("field2", "value")) .should(QueryBuilders.termQuery("field2", "value"))
) )
@ -223,7 +223,7 @@ public class FieldLevelSecurityRandomTests extends SecurityIntegTestCase {
actual = client().filterWithHeader(Collections.singletonMap(BASIC_AUTH_HEADER, basicAuthHeaderValue("user4", USERS_PASSWD))) actual = client().filterWithHeader(Collections.singletonMap(BASIC_AUTH_HEADER, basicAuthHeaderValue("user4", USERS_PASSWD)))
.prepareSearch("test") .prepareSearch("test")
.addSort("_uid", SortOrder.ASC) .addSort("_id", SortOrder.ASC)
.setQuery(QueryBuilders.boolQuery() .setQuery(QueryBuilders.boolQuery()
.should(QueryBuilders.termQuery("field1", "value")) .should(QueryBuilders.termQuery("field1", "value"))
.should(QueryBuilders.termQuery("field2", "value")) .should(QueryBuilders.termQuery("field2", "value"))
@ -231,7 +231,7 @@ public class FieldLevelSecurityRandomTests extends SecurityIntegTestCase {
) )
.get(); .get();
expected = client().prepareSearch("test") expected = client().prepareSearch("test")
.addSort("_uid", SortOrder.ASC) .addSort("_id", SortOrder.ASC)
.setQuery(QueryBuilders.boolQuery() .setQuery(QueryBuilders.boolQuery()
.should(QueryBuilders.termQuery("field3", "value")) .should(QueryBuilders.termQuery("field3", "value"))
) )

View File

@ -1219,22 +1219,7 @@ public class FieldLevelSecurityTests extends SecurityIntegTestCase {
assertThat(response.getResponses()[0].getResponse().getFields().terms("field2").size(), equalTo(1L)); assertThat(response.getResponses()[0].getResponse().getFields().terms("field2").size(), equalTo(1L));
} }
public void testParentChild_parentField() { public void testParentChild() throws Exception {
assertAcked(prepareCreate("test")
.setSettings(Settings.builder().put("index.version.created", Version.V_5_6_0.id))
.addMapping("parent")
.addMapping("child", "_parent", "type=parent"));
ensureGreen();
// index simple data
client().prepareIndex("test", "parent", "p1").setSource("{}", XContentType.JSON).get();
client().prepareIndex("test", "child", "c1").setSource("field1", "red").setParent("p1").get();
client().prepareIndex("test", "child", "c2").setSource("field1", "yellow").setParent("p1").get();
refresh();
verifyParentChild();
}
public void testParentChild_joinField() throws Exception {
XContentBuilder mapping = XContentFactory.jsonBuilder().startObject() XContentBuilder mapping = XContentFactory.jsonBuilder().startObject()
.startObject("properties") .startObject("properties")
.startObject("join_field") .startObject("join_field")