Skip to content

Commit

Permalink
Fix exists queries on nested flat_object fields throw exception
Browse files Browse the repository at this point in the history
Signed-off-by: kkewwei <[email protected]>
Signed-off-by: kkewwei <[email protected]>
  • Loading branch information
kkewwei committed Jan 22, 2025
1 parent 2794655 commit d955649
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
- Fix multi-value sort for unsigned long ([#16732](https://github.com/opensearch-project/OpenSearch/pull/16732))
- The `phone-search` analyzer no longer emits the tel/sip prefix, international calling code, extension numbers and unformatted input as a token ([#16993](https://github.com/opensearch-project/OpenSearch/pull/16993))
- Fix GRPC AUX_TRANSPORT_PORT and SETTING_GRPC_PORT settings and remove lingering HTTP terminology ([#17037](https://github.com/opensearch-project/OpenSearch/pull/17037))
- Fix exists queries on nested flat_object fields throws exception ([#16803](https://github.com/opensearch-project/OpenSearch/pull/16803))

### Security

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,26 @@ teardown:
- do:
indices.delete:
index: test

---
"Exist query in root field":
- skip:
version: "- 2.99.99"
reason: "the query would throw exception prior to 2.99.99"

- do:
search:
body: {
_source: true,
size: 10,
query: {
exists: {
field: "catalog"
}
}
}
- length: { hits.hits: 2 }

---
"Invalid docs":
- skip:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,12 @@ public static class Defaults {

@Override
public MappedFieldType keyedFieldType(String key) {
return new FlatObjectFieldType(this.name() + DOT_SYMBOL + key, this.name(), valueFieldType, valueAndPathFieldType);
return new FlatObjectFieldType(
Strings.isNullOrEmpty(key) ? this.name() : (this.name() + DOT_SYMBOL + key),
this.name(),
valueFieldType,
valueAndPathFieldType
);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import org.apache.lucene.search.TermQuery;
import org.apache.lucene.util.BytesRef;
import org.opensearch.common.TriFunction;
import org.opensearch.common.util.set.Sets;
import org.opensearch.common.xcontent.XContentFactory;
import org.opensearch.common.xcontent.json.JsonXContent;
import org.opensearch.core.xcontent.ToXContent;
Expand All @@ -27,6 +28,7 @@

import java.io.IOException;
import java.util.List;
import java.util.Set;

import static org.opensearch.index.mapper.FlatObjectFieldMapper.CONTENT_TYPE;
import static org.opensearch.index.mapper.FlatObjectFieldMapper.VALUE_AND_PATH_SUFFIX;
Expand Down Expand Up @@ -397,7 +399,14 @@ public void testFetchDocValues() throws IOException {
Throwable throwable = assertThrows(IllegalArgumentException.class, () -> ft.docValueFormat(null, null));
assertEquals("Field [field] of type [flat_object] does not support doc_value in root field", throwable.getMessage());
}
}

public void testPatternMatch() throws IOException {
MapperService mapperService = createMapperService(fieldMapping(this::minimalMapping));
QueryShardContext queryShardContext = createQueryShardContext(mapperService);
Set<String> fields = queryShardContext.simpleMatchToIndexNames("field.*");
assertEquals(2, fields.size());
assertEquals(Sets.newHashSet("field._value", "field._valueAndPath"), fields);
}

@Override
Expand Down

0 comments on commit d955649

Please sign in to comment.