Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix exists queries on nested flat_object fields throws exception #16803

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
- [Tiered Caching] Fix bug in cache stats API ([#16560](https://github.com/opensearch-project/OpenSearch/pull/16560))
- Bound the size of cache in deprecation logger ([16702](https://github.com/opensearch-project/OpenSearch/issues/16702))
- Ensure consistency of system flag on IndexMetadata after diff is applied ([#16644](https://github.com/opensearch-project/OpenSearch/pull/16644))
- 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 @@ -28,6 +28,7 @@
import org.opensearch.common.unit.Fuzziness;
import org.opensearch.common.xcontent.JsonToStringXContentParser;
import org.opensearch.core.common.ParsingException;
import org.opensearch.core.common.Strings;
import org.opensearch.core.xcontent.DeprecationHandler;
import org.opensearch.core.xcontent.NamedXContentRegistry;
import org.opensearch.core.xcontent.XContentParser;
Expand Down Expand Up @@ -84,7 +85,7 @@ public static class Defaults {
@Override
public MappedFieldType keyedFieldType(String key) {
return new FlatObjectFieldType(
this.name() + DOT_SYMBOL + key,
Strings.isNullOrEmpty(key) ? this.name() : (this.name() + DOT_SYMBOL + key),
this.name(),
(KeywordFieldType) valueFieldMapper.fieldType(),
(KeywordFieldType) valueAndPathFieldMapper.fieldType()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,15 @@
import org.apache.lucene.search.Query;
import org.apache.lucene.search.TermQuery;
import org.apache.lucene.util.BytesRef;
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;
import org.opensearch.core.xcontent.XContentBuilder;
import org.opensearch.index.query.QueryShardContext;

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

import static org.opensearch.common.xcontent.JsonToStringXContentParser.VALUE_AND_PATH_SUFFIX;
import static org.opensearch.common.xcontent.JsonToStringXContentParser.VALUE_SUFFIX;
Expand Down Expand Up @@ -397,6 +399,14 @@ public void testDeduplicationValue() throws IOException {
assertEquals(new BytesRef("field.labels=3"), fieldValueAndPaths[4].binaryValue());
}

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
protected void registerParameters(ParameterChecker checker) throws IOException {
// In the future we will want to make sure parameter updates are covered.
Expand Down
Loading