Skip to content

Commit

Permalink
replace with getField (#7855)
Browse files Browse the repository at this point in the history
* replace with getField

Signed-off-by: Shinsuke Sugaya <shinsuke@apache.org>

* Update server/src/main/java/org/opensearch/index/mapper/FlatObjectFieldMapper.java

Co-authored-by: Andriy Redko <drreta@gmail.com>
Signed-off-by: Shinsuke Sugaya <shinsuke.sugaya@gmail.com>

* add import

Signed-off-by: Shinsuke Sugaya <shinsuke@apache.org>

* add PR to CHANGELOG

Signed-off-by: Shinsuke Sugaya <shinsuke@apache.org>

* move SortedSetDocValuesField addition for field type

Signed-off-by: Shinsuke Sugaya <shinsuke@apache.org>

* remove a test case for flat-object field

Signed-off-by: Shinsuke Sugaya <shinsuke@apache.org>

* remove getField

Signed-off-by: Mingshi Liu <mingshl@amazon.com>

* remove unused import

Signed-off-by: Shinsuke Sugaya <shinsuke@apache.org>

---------

Signed-off-by: Shinsuke Sugaya <shinsuke@apache.org>
Signed-off-by: Shinsuke Sugaya <shinsuke.sugaya@gmail.com>
Signed-off-by: Mingshi Liu <mingshl@amazon.com>
Co-authored-by: Andriy Redko <drreta@gmail.com>
Co-authored-by: Mingshi Liu <mingshl@amazon.com>
  • Loading branch information
3 people committed Jul 10, 2023
1 parent a15f0ed commit 828730f
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 110 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
- Fix mapping char_filter when mapping a hashtag ([#7591](https://github.com/opensearch-project/OpenSearch/pull/7591))
- Fix NPE in multiterms aggregations involving empty buckets ([#7318](https://github.com/opensearch-project/OpenSearch/pull/7318))
- Precise system clock time in MasterService debug logs ([#7902](https://github.com/opensearch-project/OpenSearch/pull/7902))
- Improve indexing performance for flat_object type ([#7855](https://github.com/opensearch-project/OpenSearch/pull/7855))

### Security

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -482,100 +482,3 @@
}]
- match: { error.root_cause.0.type: "illegal_argument_exception" }
- match: { error.root_cause.0.reason: "script score function must not produce negative scores, but got: [-9.0]"}

---

"Flat-object fields from within the scripting":
- skip:
version: " - 2.6.99"
reason: "flat_object is introduced in 2.7.0"

- do:
indices.create:
index: test
body:
mappings:
properties:
flat:
type : "flat_object"

# This document has 6 distinct parts in its flat_object field paths:
# - flat.field_1
# - flat.field_2
# - flat.field_3
# - flat.inner
# - flat.field_A
# - flat.field_B
- do:
index:
index: test
id: 1
body: {
"flat": {
"field_1": "John Doe",
"field_2": 33,
"field_3": false,
"inner": {
"field_A": ["foo", "bar"],
"field_B": false
}
}
}

- do:
index:
index: test
id: 2
body: {
"flat": {
"field_1": "Joe Public",
"field_2": 45
}
}

- do:
indices.refresh:
index: test

# It is possible to filter based on the number of distinct parts of flat_object field paths
- do:
search:
body: {
_source: true,
query: {
bool: {
filter: {
script: {
script: {
source: "doc['flat'].size() == 6",
lang: "painless"
}
}
}
}
}
}

- length: { hits.hits: 1 }
- match: { hits.hits.0._source.flat.field_1: "John Doe" }

- do:
search:
body: {
_source: true,
query: {
bool: {
filter: {
script: {
script: {
source: "doc['flat'].size() < 6",
lang: "painless"
}
}
}
}
}
}

- length: { hits.hits: 1 }
- match: { hits.hits.0._source.flat.field_1: "Joe Public" }
Original file line number Diff line number Diff line change
Expand Up @@ -659,21 +659,18 @@ private void parseValueAddFields(ParseContext context, String value, String fiel
}

if (fieldType().hasDocValues()) {
if (context.doc().getField(fieldType().name()) == null || !context.doc().getFields(fieldType().name()).equals(field)) {
if (fieldName.equals(fieldType().name())) {
context.doc().add(new SortedSetDocValuesField(fieldType().name(), binaryValue));
}
if (valueType.equals(VALUE_SUFFIX)) {
if (valueFieldMapper != null) {
context.doc().add(new SortedSetDocValuesField(fieldType().name() + VALUE_SUFFIX, binaryValue));
}
if (fieldName.equals(fieldType().name())) {
context.doc().add(new SortedSetDocValuesField(fieldType().name(), binaryValue));
}
if (valueType.equals(VALUE_SUFFIX)) {
if (valueFieldMapper != null) {
context.doc().add(new SortedSetDocValuesField(fieldType().name() + VALUE_SUFFIX, binaryValue));
}
if (valueType.equals(VALUE_AND_PATH_SUFFIX)) {
if (valueAndPathFieldMapper != null) {
context.doc().add(new SortedSetDocValuesField(fieldType().name() + VALUE_AND_PATH_SUFFIX, binaryValue));
}
}
if (valueType.equals(VALUE_AND_PATH_SUFFIX)) {
if (valueAndPathFieldMapper != null) {
context.doc().add(new SortedSetDocValuesField(fieldType().name() + VALUE_AND_PATH_SUFFIX, binaryValue));
}

}
}

Expand Down

0 comments on commit 828730f

Please sign in to comment.