Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
d8645f8
Two empty mappings reported equally in field_caps
piergm Apr 26, 2024
5841449
Update docs/changelog/107936.yaml
piergm Apr 26, 2024
ff77922
merged main, resolved conflicts
piergm Jul 12, 2024
fcba36c
iter
piergm Jul 12, 2024
db18cf7
Merge branch 'elastic:main' into Two-empty-mappings-reported-differen…
piergm Aug 26, 2024
c51bf12
updated empty mapping
piergm Aug 26, 2024
355ad09
iter
piergm Aug 26, 2024
cd8a213
Merge branch 'elastic:main' into Two-empty-mappings-reported-differen…
piergm Aug 26, 2024
16f0b9a
iter
piergm Aug 26, 2024
49cf790
more tests fix
piergm Aug 26, 2024
abf6a03
empty mapping now is {}
piergm Aug 28, 2024
aa9fa43
skip test
piergm Sep 4, 2024
ab836e9
iter
piergm Sep 4, 2024
be91090
skipping v7 tests
piergm Sep 12, 2024
c0f4671
Merge branch 'main' into Two-empty-mappings-reported-differently-in-f…
piergm Sep 12, 2024
7900199
Merge branch 'elastic:main' into empty_mappings_equals_empty_properties
piergm Oct 11, 2024
8529f37
empty mappings equals empty properties
piergm Oct 11, 2024
e150899
Update docs/changelog/114624.yaml
piergm Oct 11, 2024
619d822
Merge branch 'elastic:main' into empty_mappings_equals_empty_properties
piergm Oct 14, 2024
3312903
Merge branch 'elastic:main' into empty_mappings_equals_empty_properties
piergm Oct 14, 2024
34574de
Merge branch 'main' into empty_mappings_equals_empty_properties
elasticmachine Nov 6, 2024
81f5ec1
Merge branch 'main' into empty_mappings_equals_empty_properties
elasticmachine Nov 8, 2024
6d27653
Merge branch 'elastic:main' into empty_mappings_equals_empty_properties
piergm Jan 14, 2025
c6bddfc
Merge branch 'elastic:main' into empty_mappings_equals_empty_properties
piergm Jan 21, 2025
e60412d
iter
piergm Jan 21, 2025
a9d4324
Merge branch 'elastic:main' into empty_mappings_equals_empty_properties
piergm Feb 21, 2025
f409d60
refactor
piergm Feb 21, 2025
575e6d8
Merge branch 'elastic:main' into empty_mappings_equals_empty_properties
piergm Feb 21, 2025
6d8c5fb
Merge branch 'main' into empty_mappings_equals_empty_properties
piergm Aug 4, 2025
a77a389
poorly formatted properties should return 400
piergm Aug 6, 2025
b07d118
[CI] Auto commit changes from spotless
Aug 6, 2025
ef8fa38
always wrapping with _doc if empty
piergm Aug 6, 2025
b532d2c
Merge branch 'empty_mappings_equals_empty_properties' of github.com:p…
piergm Aug 6, 2025
941a64a
Merge branch 'main' into empty_mappings_equals_empty_properties
piergm Aug 12, 2025
9550933
updated default mappings
piergm Aug 22, 2025
6dc4a7c
Merge branch 'empty_mappings_equals_empty_properties' of github.com:p…
piergm Aug 22, 2025
ee0f609
Merge branch 'main' into empty_mappings_equals_empty_properties
piergm Aug 22, 2025
37e3891
updated EMPTY_MAPPINGS
piergm Aug 22, 2025
1a4857d
iter n.235
piergm Aug 22, 2025
e293138
iter
piergm Aug 22, 2025
e69ac0c
Merge branch 'main' into empty_mappings_equals_empty_properties
piergm Aug 22, 2025
2fe166e
revert test
piergm Aug 26, 2025
eeedde6
Merge branch 'empty_mappings_equals_empty_properties' of github.com:p…
piergm Aug 26, 2025
718b937
Merge branch 'main' into empty_mappings_equals_empty_properties
piergm Aug 26, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions docs/changelog/114624.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
pr: 114624
summary: Empty mappings equals empty properties
area: Search
type: enhancement
issues:
- 107031
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,22 @@ public void testTwoEmptyEqualMappings() throws Exception {
assertEquals(fieldCapsResp1.get(), fieldCapsResp2.get());
}

public void testEmptyMappingsEqualsEmptyProperties() throws Exception {
assertAcked(
prepareCreate("test1").setMapping(XContentFactory.jsonBuilder().startObject().startObject("properties").endObject().endObject())
);
assertAcked(prepareCreate("test2").setMapping(XContentFactory.jsonBuilder().startObject().endObject()));
FieldCapabilitiesRequest fieldCapsReq1 = new FieldCapabilitiesRequest();
fieldCapsReq1.indices("test1");
fieldCapsReq1.fields("*");
FieldCapabilitiesResponse fieldCapsResp1 = internalCluster().coordOnlyNodeClient().fieldCaps(fieldCapsReq1).actionGet();
FieldCapabilitiesRequest fieldCapsReq2 = new FieldCapabilitiesRequest();
fieldCapsReq2.indices("test2");
fieldCapsReq2.fields("*");
FieldCapabilitiesResponse fieldCapsResp2 = internalCluster().coordOnlyNodeClient().fieldCaps(fieldCapsReq2).actionGet();
assertEquals(fieldCapsResp1.get(), fieldCapsResp2.get());
}

public void testInvalidShardCountSettings() throws Exception {
int value = randomIntBetween(-10, 0);
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -284,9 +284,9 @@ private CreateIndexRequest mapping(BytesReference source, XContentType xContentT
}

private CreateIndexRequest mapping(String type, Map<String, ?> source) {
if (source.isEmpty()) {
if (isSourceEffectivelyEmpty(source)) {
// If no source is provided we return empty mappings
return mapping(EMPTY_MAPPINGS);
source = Map.of();
} else if (source.size() != 1 || source.containsKey(type) == false) {
// wrap it in a type map if its not
source = Map.of(MapperService.SINGLE_MAPPING_NAME, source);
Expand All @@ -303,6 +303,27 @@ private CreateIndexRequest mapping(String type, Map<String, ?> source) {
}
}

/**
* Checks if the source map is effectively empty.
*
* @param source the source map to check
* @return true if the source map is empty or contains only an empty "properties" key, false otherwise
*/
private boolean isSourceEffectivelyEmpty(Map<String, ?> source) {
if (source == null) {
return true;
}
if (source.isEmpty()) {
return true;
}
if (source.size() == 1 && source.containsKey("properties")) {
if (source.get("properties") instanceof Map<?, ?> properties) {
return properties.isEmpty();
}
}
return false;
}

/**
* The cause for this index creation.
*/
Expand Down