Skip to content

Commit

Permalink
fix test
Browse files Browse the repository at this point in the history
Signed-off-by: kkewwei <kkewwei@163.com>
  • Loading branch information
kkewwei committed Jun 4, 2024
1 parent 99317c4 commit ad0962d
Show file tree
Hide file tree
Showing 3 changed files with 139 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
# The test setup includes:
# - Create flat_object mapping for test_flat_object index to test five parameters:
# - Create test_flat_object1 index to test edge cases:
# - Create test_flat_object1,test_flat_object2 index to test edge cases:
# - Index example documents
# - Refresh the index so it is ready for search tests

Expand Down Expand Up @@ -68,6 +68,18 @@ setup:
}
}

- do:
index:
index: test_flat_object
id: 4
body: {
"issue": {
"labels": {
"age1":null
}
}
}

- do:
indices.refresh:
index: test_flat_object
Expand Down Expand Up @@ -102,6 +114,44 @@ setup:
indices.refresh:
index: test_flat_object1

# index test_flat_object2
- do:
indices.create:
index: test_flat_object2
body:
mappings:
properties:
issue:
properties:
labels:
type: flat_object

- do:
index:
index: test_flat_object2
id: 1
body: {
"issue": {
"labels": {
"category": null
}
}
}

- do:
index:
index: test_flat_object2
id: 2
body: {
"issue": {
"labels": null
}
}

- do:
indices.refresh:
index: test_flat_object2

---
# Delete Index when connection is teardown
teardown:
Expand Down Expand Up @@ -145,7 +195,7 @@ teardown:
}
}

- length: { hits.hits: 3 }
- length: { hits.hits: 4 }

- do:
search:
Expand All @@ -158,6 +208,17 @@ teardown:

- length: { hits.hits: 1 }

- do:
search:
index: test_flat_object2,
body: {
query: {
match_all: { }
}
}

- length: { hits.hits: 2 }

# test ignore_above=4.
- do:
search:
Expand Down Expand Up @@ -211,6 +272,70 @@ teardown:
- length: { hits.hits: 1 }
- match: { hits.hits.0._source.issue.labels: null }

- do:
search:
index: test_flat_object,
body: {
_source: true,
query: {
exists: { field: "issue.labels" }
}
}

- length: { hits.hits: 1 }
- match: { hits.hits.0._source.issue.labels: null }

# test null_value="abc" and subField=null.
- do:
search:
index: test_flat_object,
body: {
_source: true,
query: {
term: { issue.labels.age1: "abc" }
}
}

- length: { hits.hits: 0 }

# null_value="abc" doesn't work on th subField
- do:
search:
index: test_flat_object,
body: {
_source: true,
query: {
exists: { field: "issue.labels.age1" }
}
}

- length: { hits.hits: 0 }

# test null_value=null and subField=null.
- do:
search:
index: test_flat_object2,
body: {
_source: true,
query: {
exists: { field: "issue.labels" }
}
}

- length: { hits.hits: 0 }

- do:
search:
index: test_flat_object2,
body: {
_source: true,
query: {
exists: { field: "issue.labels.category" }
}
}

- length: { hits.hits: 0 }

# test depth_limit=3.
- do:
search:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,10 @@ private void parseToken(StringBuilder path, String currentFieldName, int depth)
if (parseValue(parsedFields)) {
this.valueList.add(parsedFields.toString());
this.valueAndPathList.add(path + EQUAL_SYMBOL + parsedFields);
} else {
// it means that the value is invalid, we should delete the key from keyList.
assert this.keyList.size() > 0;
this.keyList.remove(keyList.size() - 1);
}
int dotIndex = path.lastIndexOf(DOT_SYMBOL, path.length());
if (dotIndex != -1 && path.length() > currentFieldName.length()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -196,12 +196,20 @@ public void testIgnoreAbove() throws IOException {
}

public void testNullValue() throws IOException {
// test root field is null
DocumentMapper mapper = createDocumentMapper(fieldMapping(this::minimalMapping));
ParsedDocument doc = mapper.parse(source(b -> b.nullField("field")));
assertArrayEquals(new IndexableField[0], doc.rootDoc().getFields("field"));
assertArrayEquals(new IndexableField[0], doc.rootDoc().getFields("field" + VALUE_SUFFIX));
assertArrayEquals(new IndexableField[0], doc.rootDoc().getFields("field" + VALUE_AND_PATH_SUFFIX));

// test subField is null
String json = XContentFactory.jsonBuilder().startObject().startObject("field").nullField("Foo").endObject().endObject().toString();
doc = mapper.parse(source(json));
assertArrayEquals(new IndexableField[0], doc.rootDoc().getFields("field"));
assertArrayEquals(new IndexableField[0], doc.rootDoc().getFields("field" + VALUE_SUFFIX));
assertArrayEquals(new IndexableField[0], doc.rootDoc().getFields("field" + VALUE_AND_PATH_SUFFIX));

mapper = createDocumentMapper(fieldMapping(b -> b.field("type", "flat_object").field("null_value", "bar")));
doc = mapper.parse(source(b -> {}));

Expand Down

0 comments on commit ad0962d

Please sign in to comment.