forked from elastic/elasticsearch
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Store arrays offsets for ip fields natively with synthetic source
Follow up of elastic#113757 and adds support to natively store array offsets for ip fields instead of falling back to ignored source.
- Loading branch information
Showing
12 changed files
with
799 additions
and
509 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
91 changes: 91 additions & 0 deletions
91
...est/java/org/elasticsearch/index/mapper/IPSyntheticSourceNativeArrayIntegrationTests.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the "Elastic License | ||
* 2.0", the "GNU Affero General Public License v3.0 only", and the "Server Side | ||
* Public License v 1"; you may not use this file except in compliance with, at | ||
* your election, the "Elastic License 2.0", the "GNU Affero General Public | ||
* License v3.0 only", or the "Server Side Public License, v 1". | ||
*/ | ||
|
||
package org.elasticsearch.index.mapper; | ||
|
||
import org.elasticsearch.common.network.NetworkAddress; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
import static org.elasticsearch.xcontent.XContentFactory.jsonBuilder; | ||
|
||
public class IPSyntheticSourceNativeArrayIntegrationTests extends NativeArrayIntegrationTestCase { | ||
|
||
@Override | ||
protected String getFieldTypeName() { | ||
return "ip"; | ||
} | ||
|
||
@Override | ||
protected String getRandomValue() { | ||
return NetworkAddress.format(randomIp(true)); | ||
} | ||
|
||
public void testSynthesizeArray() throws Exception { | ||
var arrayValues = new Object[][] { | ||
new Object[] { "192.168.1.4", "192.168.1.3", null, "192.168.1.2", null, "192.168.1.1" }, | ||
new Object[] { null, "192.168.1.2", null, "192.168.1.1" }, | ||
new Object[] { null }, | ||
new Object[] { null, null, null }, | ||
new Object[] { "192.168.1.3", "192.168.1.2", "192.168.1.1" } }; | ||
verifySyntheticArray(arrayValues); | ||
} | ||
|
||
public void testSynthesizeArrayIgnoreMalformed() throws Exception { | ||
var mapping = jsonBuilder().startObject() | ||
.startObject("properties") | ||
.startObject("field") | ||
.field("type", "ip") | ||
.field("ignore_malformed", true) | ||
.endObject() | ||
.endObject() | ||
.endObject(); | ||
// Note values that would be ignored are added at the end of arrays, | ||
// this makes testing easier as ignored values are always synthesized after regular values: | ||
var arrayValues = new Object[][] { | ||
new Object[] { null, "192.168.1.1", "192.168.1.2", "192.168.1.3", "192.168.1.4", null, "malformed" }, | ||
new Object[] { "192.168.1.1", "192.168.1.2", "malformed" }, | ||
new Object[] { "192.168.1.1", "192.168.1.1", "malformed" }, | ||
new Object[] { null, null, null, "malformed" }, | ||
new Object[] { "192.168.1.3", "192.168.1.3", "192.168.1.1", "malformed" } }; | ||
verifySyntheticArray(arrayValues, mapping, "_id", "field._ignore_malformed"); | ||
} | ||
|
||
public void testSynthesizeObjectArray() throws Exception { | ||
List<List<Object[]>> documents = new ArrayList<>(); | ||
{ | ||
List<Object[]> document = new ArrayList<>(); | ||
document.add(new Object[] { "192.168.1.3", "192.168.1.2", "192.168.1.1" }); | ||
document.add(new Object[] { "192.168.1.110", "192.168.1.109", "192.168.1.111" }); | ||
document.add(new Object[] { "192.168.1.2", "192.168.1.2", "192.168.1.1" }); | ||
documents.add(document); | ||
} | ||
{ | ||
List<Object[]> document = new ArrayList<>(); | ||
document.add(new Object[] { "192.168.1.9", "192.168.1.7", "192.168.1.5" }); | ||
document.add(new Object[] { "192.168.1.2", "192.168.1.4", "192.168.1.6" }); | ||
document.add(new Object[] { "192.168.1.7", "192.168.1.6", "192.168.1.5" }); | ||
documents.add(document); | ||
} | ||
verifySyntheticObjectArray(documents); | ||
} | ||
|
||
public void testSynthesizeArrayInObjectField() throws Exception { | ||
List<Object[]> documents = new ArrayList<>(); | ||
documents.add(new Object[] { "192.168.1.254", "192.168.1.253", "192.168.1.252" }); | ||
documents.add(new Object[] { "192.168.1.112", "192.168.1.113", "192.168.1.114" }); | ||
documents.add(new Object[] { "192.168.1.3", "192.168.1.2", "192.168.1.1" }); | ||
documents.add(new Object[] { "192.168.1.9", "192.168.1.7", "192.168.1.5" }); | ||
documents.add(new Object[] { "192.168.1.2", "192.168.1.4", "192.168.1.6" }); | ||
documents.add(new Object[] { "192.168.1.7", "192.168.1.6", "192.168.1.5" }); | ||
verifySyntheticArrayInObject(documents); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.