Skip to content

Commit

Permalink
Merge branch 'main' into improve-task-avoidance
Browse files Browse the repository at this point in the history
  • Loading branch information
mark-vieira committed Oct 18, 2023
2 parents 10926ae + baf251e commit d5626be
Show file tree
Hide file tree
Showing 18 changed files with 725 additions and 453 deletions.
6 changes: 6 additions & 0 deletions docs/changelog/100642.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
pr: 100642
summary: "ESQL: Alias duplicated aggregations in a stats"
area: ES|QL
type: enhancement
issues:
- 100544
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertHitCount;
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertNoFailures;
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertSearchHit;
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertSearchHits;
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertSearchHitsWithoutFailures;
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.hasId;
import static org.elasticsearch.xcontent.XContentFactory.jsonBuilder;
import static org.hamcrest.Matchers.containsString;
Expand Down Expand Up @@ -612,18 +612,17 @@ public void testInnerHitsWithIgnoreUnmapped() {
createIndexRequest("index1", "child_type", "2", "1").get();
client().prepareIndex("index2").setId("3").setSource("key", "value").get();
refresh();

SearchResponse response = client().prepareSearch("index1", "index2")
.setQuery(
boolQuery().should(
hasChildQuery("child_type", matchAllQuery(), ScoreMode.None).ignoreUnmapped(true)
.innerHit(new InnerHitBuilder().setIgnoreUnmapped(true))
).should(termQuery("key", "value"))
)
.get();
assertNoFailures(response);
assertHitCount(response, 2);
assertSearchHits(response, "1", "3");
assertSearchHitsWithoutFailures(
client().prepareSearch("index1", "index2")
.setQuery(
boolQuery().should(
hasChildQuery("child_type", matchAllQuery(), ScoreMode.None).ignoreUnmapped(true)
.innerHit(new InnerHitBuilder().setIgnoreUnmapped(true))
).should(termQuery("key", "value"))
),
"1",
"3"
);
}

public void testTooHighResultWindow() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@

import org.apache.lucene.search.Query;
import org.apache.lucene.search.join.ScoreMode;
import org.elasticsearch.action.search.SearchResponse;
import org.elasticsearch.action.support.WriteRequest;
import org.elasticsearch.common.bytes.BytesReference;
import org.elasticsearch.common.settings.Settings;
Expand Down Expand Up @@ -47,7 +46,7 @@
import static org.elasticsearch.index.query.QueryBuilders.scriptQuery;
import static org.elasticsearch.index.query.QueryBuilders.termQuery;
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertHitCount;
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertSearchHits;
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertSearchHitsWithoutFailures;
import static org.elasticsearch.xcontent.XContentFactory.jsonBuilder;
import static org.hamcrest.Matchers.equalTo;

Expand Down Expand Up @@ -87,17 +86,17 @@ public void testPercolateScriptQuery() throws IOException {
.setRefreshPolicy(WriteRequest.RefreshPolicy.IMMEDIATE)
.execute()
.actionGet();
SearchResponse response = client().prepareSearch("index")
.setQuery(
new PercolateQueryBuilder(
"query",
BytesReference.bytes(jsonBuilder().startObject().field("field1", "b").endObject()),
XContentType.JSON
)
)
.get();
assertHitCount(response, 1);
assertSearchHits(response, "1");
assertSearchHitsWithoutFailures(
client().prepareSearch("index")
.setQuery(
new PercolateQueryBuilder(
"query",
BytesReference.bytes(jsonBuilder().startObject().field("field1", "b").endObject()),
XContentType.JSON
)
),
"1"
);
}

public void testPercolateQueryWithNestedDocuments_doNotLeakBitsetCacheEntries() throws Exception {
Expand Down Expand Up @@ -265,17 +264,17 @@ public void testMapUnmappedFieldAsText() throws IOException {
.get();
indicesAdmin().prepareRefresh().get();

SearchResponse response = client().prepareSearch("test")
.setQuery(
new PercolateQueryBuilder(
"query",
BytesReference.bytes(jsonBuilder().startObject().field("field1", "value").endObject()),
XContentType.JSON
)
)
.get();
assertHitCount(response, 1);
assertSearchHits(response, "1");
assertSearchHitsWithoutFailures(
client().prepareSearch("test")
.setQuery(
new PercolateQueryBuilder(
"query",
BytesReference.bytes(jsonBuilder().startObject().field("field1", "value").endObject()),
XContentType.JSON
)
),
"1"
);
}

public void testRangeQueriesWithNow() throws Exception {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public void testDelete() throws InterruptedException, ExecutionException {
DeleteResponse delete = client().prepareDelete("test", "1").setRefreshPolicy(RefreshPolicy.WAIT_UNTIL).get();
assertEquals(DocWriteResponse.Result.DELETED, delete.getResult());
assertFalse("request shouldn't have forced a refresh", delete.forcedRefresh());
assertNoSearchHits(client().prepareSearch("test").setQuery(matchQuery("foo", "bar")).get());
assertNoSearchHits(client().prepareSearch("test").setQuery(matchQuery("foo", "bar")));
}

public void testUpdate() throws InterruptedException, ExecutionException {
Expand Down Expand Up @@ -109,7 +109,7 @@ public void testUpdate() throws InterruptedException, ExecutionException {
.get();
assertEquals(2, update.getVersion());
assertFalse("request shouldn't have forced a refresh", update.forcedRefresh());
assertNoSearchHits(client().prepareSearch("test").setQuery(matchQuery("foo", "cat")).get());
assertNoSearchHits(client().prepareSearch("test").setQuery(matchQuery("foo", "cat")));
}

public void testBulk() {
Expand All @@ -129,7 +129,7 @@ public void testBulk() {
bulk = client().prepareBulk().setRefreshPolicy(RefreshPolicy.WAIT_UNTIL);
bulk.add(client().prepareDelete("test", "1"));
assertBulkSuccess(bulk.get());
assertNoSearchHits(client().prepareSearch("test").setQuery(matchQuery("foo", "bar")).get());
assertNoSearchHits(client().prepareSearch("test").setQuery(matchQuery("foo", "bar")));

// Update makes a noop
bulk = client().prepareBulk().setRefreshPolicy(RefreshPolicy.WAIT_UNTIL);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ private void runTestAutomaticRefresh(final IntToLongFunction count) throws Inter
assertFalse(indexService.getIndexSettings().isExplicitRefresh());
ensureGreen();
AtomicInteger totalNumDocs = new AtomicInteger(Integer.MAX_VALUE);
assertNoSearchHits(client().prepareSearch().get());
assertNoSearchHits(client().prepareSearch());
int numDocs = scaledRandomIntBetween(25, 100);
totalNumDocs.set(numDocs);
CountDownLatch indexingDone = new CountDownLatch(numDocs);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import org.elasticsearch.cluster.routing.allocation.decider.EnableAllocationDecider;
import org.elasticsearch.cluster.service.ClusterService;
import org.elasticsearch.common.Priority;
import org.elasticsearch.common.Strings;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.core.Nullable;
import org.elasticsearch.core.TimeValue;
Expand Down Expand Up @@ -79,7 +80,7 @@
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked;
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertHitCount;
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertNoFailures;
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertSearchHits;
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertSearchHitsWithoutFailures;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.everyItem;
import static org.hamcrest.Matchers.in;
Expand Down Expand Up @@ -522,9 +523,7 @@ public void testIndexSearchAndRelocateConcurrently() throws Exception {
final int numIters = randomIntBetween(10, 20);
for (int i = 0; i < numIters; i++) {
logger.info(" --> checking iteration {}", i);
SearchResponse afterRelocation = client().prepareSearch().setSize(ids.size()).get();
assertNoFailures(afterRelocation);
assertSearchHits(afterRelocation, ids.toArray(new String[ids.size()]));
assertSearchHitsWithoutFailures(client().prepareSearch().setSize(ids.size()), ids.toArray(Strings.EMPTY_ARRAY));
}
stopped.set(true);
for (Thread searchThread : searchThreads) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertHitCount;
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertNoFailures;
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertSearchHit;
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertSearchHits;
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertSearchHitsWithoutFailures;
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.hasId;
import static org.elasticsearch.xcontent.XContentFactory.jsonBuilder;
import static org.hamcrest.Matchers.containsString;
Expand Down Expand Up @@ -922,17 +922,17 @@ public void testInnerHitsWithIgnoreUnmapped() throws Exception {
client().prepareIndex("index2").setId("3").setSource("key", "value").get();
refresh();

SearchResponse response = client().prepareSearch("index1", "index2")
.setQuery(
boolQuery().should(
nestedQuery("nested_type", matchAllQuery(), ScoreMode.None).ignoreUnmapped(true)
.innerHit(new InnerHitBuilder().setIgnoreUnmapped(true))
).should(termQuery("key", "value"))
)
.get();
assertNoFailures(response);
assertHitCount(response, 2);
assertSearchHits(response, "1", "3");
assertSearchHitsWithoutFailures(
client().prepareSearch("index1", "index2")
.setQuery(
boolQuery().should(
nestedQuery("nested_type", matchAllQuery(), ScoreMode.None).ignoreUnmapped(true)
.innerHit(new InnerHitBuilder().setIgnoreUnmapped(true))
).should(termQuery("key", "value"))
),
"1",
"3"
);
}

public void testUseMaxDocInsteadOfSize() throws Exception {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertFirstHit;
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertHitCount;
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertNoFailures;
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertSearchHits;
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertSearchHitsWithoutFailures;
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertSecondHit;
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.hasId;
import static org.hamcrest.Matchers.anyOf;
Expand Down Expand Up @@ -348,17 +348,18 @@ public void testPhraseType() {
.get();
assertThat(searchResponse.getHits().getTotalHits().value, greaterThan(1L));

searchResponse = client().prepareSearch("test")
.setQuery(
randomizeType(
multiMatchQuery("the Ul", "full_name_phrase", "first_name_phrase", "last_name_phrase", "category_phrase").operator(
Operator.OR
).type(MatchQueryParser.Type.PHRASE_PREFIX)
)
)
.get();
assertSearchHits(searchResponse, "ultimate2", "ultimate1");
assertHitCount(searchResponse, 2L);
assertSearchHitsWithoutFailures(
client().prepareSearch("test")
.setQuery(
randomizeType(
multiMatchQuery("the Ul", "full_name_phrase", "first_name_phrase", "last_name_phrase", "category_phrase").operator(
Operator.OR
).type(MatchQueryParser.Type.PHRASE_PREFIX)
)
),
"ultimate2",
"ultimate1"
);
}

public void testSingleField() throws NoSuchFieldException, IllegalAccessException {
Expand Down
Loading

0 comments on commit d5626be

Please sign in to comment.