[TEST] move filters aggs wrapper query builder rewriting test to integ tests
This test makes little sense when sent from the REST layer, as WrapperQueryBuilder is supposed to be used from the Java api. Also, providing the inner query as base64 string will work only for string formats and break for binary formats like SMILE and CBOR, whcih doesn't play well with randomizing content type in our REST tests
This commit is contained in:
parent
ca858befab
commit
261f31f5b7
|
@ -0,0 +1,67 @@
|
|||
/*
|
||||
* Licensed to Elasticsearch under one or more contributor
|
||||
* license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright
|
||||
* ownership. Elasticsearch licenses this file to you under
|
||||
* the Apache License, Version 2.0 (the "License"); you may
|
||||
* not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
package org.elasticsearch.search.aggregations;
|
||||
|
||||
import org.elasticsearch.action.search.SearchResponse;
|
||||
import org.elasticsearch.common.bytes.BytesReference;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||
import org.elasticsearch.common.xcontent.XContentFactory;
|
||||
import org.elasticsearch.common.xcontent.XContentType;
|
||||
import org.elasticsearch.index.query.WrapperQueryBuilder;
|
||||
import org.elasticsearch.search.aggregations.bucket.filters.FiltersAggregationBuilder;
|
||||
import org.elasticsearch.search.aggregations.bucket.filters.FiltersAggregator;
|
||||
import org.elasticsearch.search.aggregations.bucket.filters.InternalFilters;
|
||||
import org.elasticsearch.test.ESSingleNodeTestCase;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
public class FiltersAggsRewriteIT extends ESSingleNodeTestCase {
|
||||
|
||||
public void testWrapperQueryIsRewritten() throws IOException {
|
||||
createIndex("test", Settings.EMPTY, "test", "title", "type=text");
|
||||
client().prepareIndex("test", "test", "1").setSource("title", "foo bar baz").get();
|
||||
client().prepareIndex("test", "test", "2").setSource("title", "foo foo foo").get();
|
||||
client().prepareIndex("test", "test", "3").setSource("title", "bar baz bax").get();
|
||||
client().admin().indices().prepareRefresh("test").get();
|
||||
|
||||
XContentType xContentType = randomFrom(XContentType.values());
|
||||
BytesReference bytesReference;
|
||||
try (XContentBuilder builder = XContentFactory.contentBuilder(xContentType)) {
|
||||
builder.startObject();
|
||||
{
|
||||
builder.startObject("terms");
|
||||
{
|
||||
builder.array("title", "foo");
|
||||
}
|
||||
builder.endObject();
|
||||
}
|
||||
builder.endObject();
|
||||
bytesReference = builder.bytes();
|
||||
}
|
||||
FiltersAggregationBuilder builder = new FiltersAggregationBuilder("titles", new FiltersAggregator.KeyedFilter("titleterms",
|
||||
new WrapperQueryBuilder(bytesReference)));
|
||||
SearchResponse searchResponse = client().prepareSearch("test").setSize(0).addAggregation(builder).get();
|
||||
assertEquals(3, searchResponse.getHits().getTotalHits());
|
||||
InternalFilters filters = searchResponse.getAggregations().get("titles");
|
||||
assertEquals(1, filters.getBuckets().size());
|
||||
assertEquals(2, filters.getBuckets().get(0).getDocCount());
|
||||
}
|
||||
}
|
|
@ -1,52 +0,0 @@
|
|||
setup:
|
||||
- do:
|
||||
indices.create:
|
||||
index: test
|
||||
body:
|
||||
settings:
|
||||
number_of_shards: 1
|
||||
number_of_replicas: 0
|
||||
mappings:
|
||||
post:
|
||||
properties:
|
||||
title:
|
||||
type: text
|
||||
|
||||
- do:
|
||||
index:
|
||||
index: test
|
||||
type: test
|
||||
id: 1
|
||||
body: { "title" : "foo bar baz" }
|
||||
|
||||
- do:
|
||||
index:
|
||||
index: test
|
||||
type: test
|
||||
id: 2
|
||||
body: { "title" : "foo foo foo" }
|
||||
|
||||
- do:
|
||||
index:
|
||||
index: test
|
||||
type: test
|
||||
id: 3
|
||||
body: { "title" : "bar baz bax" }
|
||||
|
||||
- do:
|
||||
indices.refresh: {}
|
||||
|
||||
---
|
||||
"Filters aggs with wrapper query":
|
||||
- skip:
|
||||
version: " - 5.1.1"
|
||||
reason: Using filters aggs that needs rewriting, this was fixed in 5.1.2
|
||||
|
||||
- do:
|
||||
search:
|
||||
body: {"size": 0, "aggs": {"titles": {"filters": {"filters" : {"titleterms" : {"wrapper" : {"query": "eyJ0ZXJtcyIgOiB7ICJ0aXRsZSI6IFsiZm9vIl0gfX0="}}}}}}}
|
||||
|
||||
# validate result
|
||||
- match: { hits.total: 3 }
|
||||
- length: { aggregations.titles.buckets: 1 }
|
||||
- match: { aggregations.titles.buckets.titleterms.doc_count: 2 }
|
Loading…
Reference in New Issue