|
@@ -21,6 +21,8 @@ import org.elasticsearch.index.query.ConstantScoreQueryBuilder;
|
|
|
import org.elasticsearch.index.query.TermQueryBuilder;
|
|
|
import org.elasticsearch.index.query.TermsQueryBuilder;
|
|
|
import org.elasticsearch.ingest.IngestDocument;
|
|
|
+import org.elasticsearch.ingest.TestTemplateService;
|
|
|
+import org.elasticsearch.script.TemplateScript;
|
|
|
import org.elasticsearch.search.SearchHit;
|
|
|
import org.elasticsearch.search.SearchHits;
|
|
|
import org.elasticsearch.search.aggregations.Aggregations;
|
|
@@ -47,7 +49,17 @@ public class MatchProcessorTests extends ESTestCase {
|
|
|
public void testBasics() throws Exception {
|
|
|
int maxMatches = randomIntBetween(1, 8);
|
|
|
MockSearchFunction mockSearch = mockedSearchFunction(Map.of("elastic.co", Map.of("globalRank", 451, "tldRank", 23, "tld", "co")));
|
|
|
- MatchProcessor processor = new MatchProcessor("_tag", mockSearch, "_name", "domain", "entry", true, false, "domain", maxMatches);
|
|
|
+ MatchProcessor processor = new MatchProcessor(
|
|
|
+ "_tag",
|
|
|
+ mockSearch,
|
|
|
+ "_name",
|
|
|
+ str("domain"),
|
|
|
+ str("entry"),
|
|
|
+ true,
|
|
|
+ false,
|
|
|
+ "domain",
|
|
|
+ maxMatches
|
|
|
+ );
|
|
|
IngestDocument ingestDocument = new IngestDocument(
|
|
|
"_index",
|
|
|
"_id",
|
|
@@ -91,7 +103,7 @@ public class MatchProcessorTests extends ESTestCase {
|
|
|
|
|
|
public void testNoMatch() throws Exception {
|
|
|
MockSearchFunction mockSearch = mockedSearchFunction();
|
|
|
- MatchProcessor processor = new MatchProcessor("_tag", mockSearch, "_name", "domain", "entry", true, false, "domain", 1);
|
|
|
+ MatchProcessor processor = new MatchProcessor("_tag", mockSearch, "_name", str("domain"), str("entry"), true, false, "domain", 1);
|
|
|
IngestDocument ingestDocument = new IngestDocument(
|
|
|
"_index",
|
|
|
"_id",
|
|
@@ -127,7 +139,7 @@ public class MatchProcessorTests extends ESTestCase {
|
|
|
public void testSearchFailure() throws Exception {
|
|
|
String indexName = ".enrich-_name";
|
|
|
MockSearchFunction mockSearch = mockedSearchFunction(new IndexNotFoundException(indexName));
|
|
|
- MatchProcessor processor = new MatchProcessor("_tag", mockSearch, "_name", "domain", "entry", true, false, "domain", 1);
|
|
|
+ MatchProcessor processor = new MatchProcessor("_tag", mockSearch, "_name", str("domain"), str("entry"), true, false, "domain", 1);
|
|
|
IngestDocument ingestDocument = new IngestDocument(
|
|
|
"_index",
|
|
|
"_id",
|
|
@@ -171,8 +183,8 @@ public class MatchProcessorTests extends ESTestCase {
|
|
|
"_tag",
|
|
|
mockedSearchFunction(),
|
|
|
"_name",
|
|
|
- "domain",
|
|
|
- "entry",
|
|
|
+ str("domain"),
|
|
|
+ str("entry"),
|
|
|
true,
|
|
|
true,
|
|
|
"domain",
|
|
@@ -191,8 +203,8 @@ public class MatchProcessorTests extends ESTestCase {
|
|
|
"_tag",
|
|
|
mockedSearchFunction(),
|
|
|
"_name",
|
|
|
- "domain",
|
|
|
- "entry",
|
|
|
+ str("domain"),
|
|
|
+ str("entry"),
|
|
|
true,
|
|
|
false,
|
|
|
"domain",
|
|
@@ -213,7 +225,7 @@ public class MatchProcessorTests extends ESTestCase {
|
|
|
|
|
|
public void testExistingFieldWithOverrideDisabled() throws Exception {
|
|
|
MockSearchFunction mockSearch = mockedSearchFunction(Map.of("elastic.co", Map.of("globalRank", 451, "tldRank", 23, "tld", "co")));
|
|
|
- MatchProcessor processor = new MatchProcessor("_tag", mockSearch, "_name", "domain", "entry", false, false, "domain", 1);
|
|
|
+ MatchProcessor processor = new MatchProcessor("_tag", mockSearch, "_name", str("domain"), str("entry"), false, false, "domain", 1);
|
|
|
|
|
|
IngestDocument ingestDocument = new IngestDocument(new HashMap<>(Map.of("domain", "elastic.co", "tld", "tld")), Map.of());
|
|
|
IngestDocument[] resultHolder = new IngestDocument[1];
|
|
@@ -229,7 +241,7 @@ public class MatchProcessorTests extends ESTestCase {
|
|
|
|
|
|
public void testExistingNullFieldWithOverrideDisabled() throws Exception {
|
|
|
MockSearchFunction mockSearch = mockedSearchFunction(Map.of("elastic.co", Map.of("globalRank", 451, "tldRank", 23, "tld", "co")));
|
|
|
- MatchProcessor processor = new MatchProcessor("_tag", mockSearch, "_name", "domain", "entry", false, false, "domain", 1);
|
|
|
+ MatchProcessor processor = new MatchProcessor("_tag", mockSearch, "_name", str("domain"), str("entry"), false, false, "domain", 1);
|
|
|
|
|
|
Map<String, Object> source = new HashMap<>();
|
|
|
source.put("domain", "elastic.co");
|
|
@@ -248,7 +260,7 @@ public class MatchProcessorTests extends ESTestCase {
|
|
|
|
|
|
public void testNumericValue() {
|
|
|
MockSearchFunction mockSearch = mockedSearchFunction(Map.of(2, Map.of("globalRank", 451, "tldRank", 23, "tld", "co")));
|
|
|
- MatchProcessor processor = new MatchProcessor("_tag", mockSearch, "_name", "domain", "entry", false, true, "domain", 1);
|
|
|
+ MatchProcessor processor = new MatchProcessor("_tag", mockSearch, "_name", str("domain"), str("entry"), false, true, "domain", 1);
|
|
|
IngestDocument ingestDocument = new IngestDocument("_index", "_id", "_routing", 1L, VersionType.INTERNAL, Map.of("domain", 2));
|
|
|
|
|
|
// Execute
|
|
@@ -276,7 +288,7 @@ public class MatchProcessorTests extends ESTestCase {
|
|
|
MockSearchFunction mockSearch = mockedSearchFunction(
|
|
|
Map.of(List.of("1", "2"), Map.of("globalRank", 451, "tldRank", 23, "tld", "co"))
|
|
|
);
|
|
|
- MatchProcessor processor = new MatchProcessor("_tag", mockSearch, "_name", "domain", "entry", false, true, "domain", 1);
|
|
|
+ MatchProcessor processor = new MatchProcessor("_tag", mockSearch, "_name", str("domain"), str("entry"), false, true, "domain", 1);
|
|
|
IngestDocument ingestDocument = new IngestDocument(
|
|
|
"_index",
|
|
|
"_id",
|
|
@@ -385,4 +397,8 @@ public class MatchProcessorTests extends ESTestCase {
|
|
|
new SearchResponse.Clusters(1, 1, 0)
|
|
|
);
|
|
|
}
|
|
|
+
|
|
|
+ static TemplateScript.Factory str(String stringLiteral) {
|
|
|
+ return new TestTemplateService.MockTemplateScript.Factory(stringLiteral);
|
|
|
+ }
|
|
|
}
|