Skip to content

Commit

Permalink
Merge branch 'main' of https://github.com/elastic/elasticsearch into …
Browse files Browse the repository at this point in the history
…telemetry_add_commands
  • Loading branch information
astefan committed Dec 4, 2023
2 parents 98c32dd + 143f420 commit 65bb8d2
Show file tree
Hide file tree
Showing 80 changed files with 1,954 additions and 1,618 deletions.
8 changes: 8 additions & 0 deletions distribution/tools/plugin-cli/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
* Side Public License, v 1.
*/

import org.elasticsearch.gradle.OS

apply plugin: 'elasticsearch.build'

base {
Expand Down Expand Up @@ -38,6 +40,12 @@ tasks.named("dependencyLicenses").configure {
tasks.named("test").configure {
// TODO: find a way to add permissions for the tests in this module
systemProperty 'tests.security.manager', 'false'
// These tests are "heavy" on the secure number generator. On Linux, the NativePRNG defaults to /dev/random for the seeds, and
// its entropy is quite limited, to the point that it's known to hang: https://bugs.openjdk.org/browse/JDK-6521844
// We force the seed to be initialized from /dev/urandom, which is less secure, but in case of unit tests is not important.
if (OS.current() == OS.LINUX) {
systemProperty 'java.security.egd', 'file:/dev/urandom'
}
}

/*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,6 @@
import static org.mockito.Mockito.spy;

@LuceneTestCase.SuppressFileSystems("*")
@LuceneTestCase.AwaitsFix(bugUrl = "https://github.com/elastic/elasticsearch/issues/102783")
public class InstallPluginActionTests extends ESTestCase {

private InstallPluginAction skipJarHellAction;
Expand Down
6 changes: 6 additions & 0 deletions docs/changelog/102934.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
pr: 102934
summary: Ensure transform updates only modify the expected transform task
area: Transform
type: bug
issues:
- 102933
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,6 @@ public void testHasParentFilter() throws Exception {
constantScoreQuery(hasParentQuery("parent", termQuery("p_field", parentToChildrenEntry.getKey()), false))
).setSize(numChildDocsPerParent),
response -> {
assertNoFailures(response);
Set<String> childIds = parentToChildrenEntry.getValue();
assertThat(response.getHits().getTotalHits().value, equalTo((long) childIds.size()));
for (int i = 0; i < response.getHits().getTotalHits().value; i++) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
import java.util.List;
import java.util.Map;

import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertNoFailuresAndResponse;
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertResponse;
import static org.hamcrest.Matchers.equalTo;

public class LookupRuntimeFieldIT extends ESIntegTestCase {
Expand Down Expand Up @@ -132,90 +134,92 @@ public void populateIndex() throws Exception {
}

public void testBasic() {
SearchResponse searchResponse = prepareSearch("books").addFetchField("author")
.addFetchField("title")
.addSort("published_date", SortOrder.DESC)
.setSize(3)
.get();
ElasticsearchAssertions.assertNoFailures(searchResponse);
ElasticsearchAssertions.assertHitCount(searchResponse, 5);
assertNoFailuresAndResponse(
prepareSearch("books").addFetchField("author").addFetchField("title").addSort("published_date", SortOrder.DESC).setSize(3),
searchResponse -> {
ElasticsearchAssertions.assertHitCount(searchResponse, 5);

SearchHit hit0 = searchResponse.getHits().getHits()[0];
assertThat(hit0.field("title").getValues(), equalTo(List.of("the fifth book")));
assertThat(
hit0.field("author").getValues(),
equalTo(List.of(Map.of("first_name", List.of("Mike"), "last_name", List.of("Boston"))))
);
SearchHit hit0 = searchResponse.getHits().getHits()[0];
assertThat(hit0.field("title").getValues(), equalTo(List.of("the fifth book")));
assertThat(
hit0.field("author").getValues(),
equalTo(List.of(Map.of("first_name", List.of("Mike"), "last_name", List.of("Boston"))))
);

SearchHit hit1 = searchResponse.getHits().getHits()[1];
assertThat(hit1.field("title").getValues(), equalTo(List.of("the forth book")));
assertThat(
hit1.field("author").getValues(),
equalTo(
List.of(
Map.of("first_name", List.of("Mike"), "last_name", List.of("Boston")),
Map.of("first_name", List.of("Jack"), "last_name", List.of("Austin"))
)
)
);
SearchHit hit1 = searchResponse.getHits().getHits()[1];
assertThat(hit1.field("title").getValues(), equalTo(List.of("the forth book")));
assertThat(
hit1.field("author").getValues(),
equalTo(
List.of(
Map.of("first_name", List.of("Mike"), "last_name", List.of("Boston")),
Map.of("first_name", List.of("Jack"), "last_name", List.of("Austin"))
)
)
);

SearchHit hit2 = searchResponse.getHits().getHits()[2];
assertThat(hit2.field("title").getValues(), equalTo(List.of("the third book")));
assertThat(
hit2.field("author").getValues(),
equalTo(List.of(Map.of("first_name", List.of("Mike"), "last_name", List.of("Boston"))))
SearchHit hit2 = searchResponse.getHits().getHits()[2];
assertThat(hit2.field("title").getValues(), equalTo(List.of("the third book")));
assertThat(
hit2.field("author").getValues(),
equalTo(List.of(Map.of("first_name", List.of("Mike"), "last_name", List.of("Boston"))))
);
}
);
}

public void testLookupMultipleIndices() throws IOException {
SearchResponse searchResponse = prepareSearch("books").setRuntimeMappings(parseMapping("""
{
"publisher": {
"type": "lookup",
"target_index": "publishers",
"input_field": "publisher_id",
"target_field": "_id",
"fetch_fields": ["name", "city"]
assertResponse(
prepareSearch("books").setRuntimeMappings(parseMapping("""
{
"publisher": {
"type": "lookup",
"target_index": "publishers",
"input_field": "publisher_id",
"target_field": "_id",
"fetch_fields": ["name", "city"]
}
}
}
"""))
.setFetchSource(false)
.addFetchField("title")
.addFetchField("author")
.addFetchField("publisher")
.addSort("published_date", SortOrder.DESC)
.setSize(2)
.get();
SearchHit hit0 = searchResponse.getHits().getHits()[0];
assertThat(hit0.field("title").getValues(), equalTo(List.of("the fifth book")));
assertThat(
hit0.field("author").getValues(),
equalTo(List.of(Map.of("first_name", List.of("Mike"), "last_name", List.of("Boston"))))
);
assertThat(
hit0.field("publisher").getValues(),
equalTo(List.of(Map.of("name", List.of("The second publisher"), "city", List.of("Toronto"))))
);
"""))
.setFetchSource(false)
.addFetchField("title")
.addFetchField("author")
.addFetchField("publisher")
.addSort("published_date", SortOrder.DESC)
.setSize(2),
searchResponse -> {
SearchHit hit0 = searchResponse.getHits().getHits()[0];
assertThat(hit0.field("title").getValues(), equalTo(List.of("the fifth book")));
assertThat(
hit0.field("author").getValues(),
equalTo(List.of(Map.of("first_name", List.of("Mike"), "last_name", List.of("Boston"))))
);
assertThat(
hit0.field("publisher").getValues(),
equalTo(List.of(Map.of("name", List.of("The second publisher"), "city", List.of("Toronto"))))
);

SearchHit hit1 = searchResponse.getHits().getHits()[1];
assertThat(hit1.field("title").getValues(), equalTo(List.of("the forth book")));
assertThat(
hit1.field("author").getValues(),
equalTo(
List.of(
Map.of("first_name", List.of("Mike"), "last_name", List.of("Boston")),
Map.of("first_name", List.of("Jack"), "last_name", List.of("Austin"))
)
)
);
assertThat(
hit1.field("publisher").getValues(),
equalTo(List.of(Map.of("name", List.of("The first publisher"), "city", List.of("Montreal", "Vancouver"))))
SearchHit hit1 = searchResponse.getHits().getHits()[1];
assertThat(hit1.field("title").getValues(), equalTo(List.of("the forth book")));
assertThat(
hit1.field("author").getValues(),
equalTo(
List.of(
Map.of("first_name", List.of("Mike"), "last_name", List.of("Boston")),
Map.of("first_name", List.of("Jack"), "last_name", List.of("Austin"))
)
)
);
assertThat(
hit1.field("publisher").getValues(),
equalTo(List.of(Map.of("name", List.of("The first publisher"), "city", List.of("Montreal", "Vancouver"))))
);
}
);
}

public void testFetchField() throws Exception {
SearchResponse searchResponse = prepareSearch("books").setRuntimeMappings(parseMapping("""
assertNoFailuresAndResponse(prepareSearch("books").setRuntimeMappings(parseMapping("""
{
"author": {
"type": "lookup",
Expand All @@ -225,12 +229,15 @@ public void testFetchField() throws Exception {
"fetch_fields": ["first_name", {"field": "joined", "format": "MM/yyyy"}]
}
}
""")).addFetchField("author").addFetchField("title").addSort("published_date", SortOrder.ASC).setSize(1).get();
ElasticsearchAssertions.assertNoFailures(searchResponse);
SearchHit hit0 = searchResponse.getHits().getHits()[0];
// "author", "john", "first_name", "John", "last_name", "New York", "joined", "2020-03-01"
assertThat(hit0.field("title").getValues(), equalTo(List.of("the first book")));
assertThat(hit0.field("author").getValues(), equalTo(List.of(Map.of("first_name", List.of("John"), "joined", List.of("03/2020")))));
""")).addFetchField("author").addFetchField("title").addSort("published_date", SortOrder.ASC).setSize(1), searchResponse -> {
SearchHit hit0 = searchResponse.getHits().getHits()[0];
// "author", "john", "first_name", "John", "last_name", "New York", "joined", "2020-03-01"
assertThat(hit0.field("title").getValues(), equalTo(List.of("the first book")));
assertThat(
hit0.field("author").getValues(),
equalTo(List.of(Map.of("first_name", List.of("John"), "joined", List.of("03/2020"))))
);
});
}

private Map<String, Object> parseMapping(String mapping) throws IOException {
Expand Down
Loading

0 comments on commit 65bb8d2

Please sign in to comment.