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

[Backport 2.x] support rangeQuery and regexpQuery in constant_keyword field type #15093

Merged
merged 1 commit into from
Aug 2, 2024
Merged
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 @@ -10,6 +10,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
- Add basic aggregation support for derived fields ([#14618](https://github.com/opensearch-project/OpenSearch/pull/14618))
- Add ThreadContextPermission for markAsSystemContext and allow core to perform the method ([#15016](https://github.com/opensearch-project/OpenSearch/pull/15016))
- Add ThreadContextPermission for stashAndMergeHeaders and stashWithOrigin ([#15039](https://github.com/opensearch-project/OpenSearch/pull/15039))
- Add `rangeQuery` and `regexpQuery` for `constant_keyword` field type ([#14711](https://github.com/opensearch-project/OpenSearch/pull/14711))

### Dependencies
- Bump `org.apache.commons:commons-lang3` from 3.14.0 to 3.15.0 ([#14861](https://github.com/opensearch-project/OpenSearch/pull/14861))
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,13 @@
# The test setup includes two parts:
# part1: test mapping and indexing
# part2: test query
---
# The test setup includes:
# - Create index with constant_keyword field type
# - Check mapping
# - Index two example documents
# - Search
# - Delete Index when connection is teardown

"Mappings and Supported queries":
"Mappings and Indexing":
- skip:
version: " - 2.15.99"
reason: "fixed in 2.16.0"

# Create index with constant_keyword field type
# Create indices with constant_keyword field type
- do:
indices.create:
index: test
Expand All @@ -22,7 +18,7 @@
type: "constant_keyword"
value: "1"

# Index document
# Index documents to test integer and string are both ok.
- do:
index:
index: test
Expand All @@ -39,6 +35,7 @@
"genre": 1
}

# Refresh
- do:
indices.refresh:
index: test
Expand All @@ -54,6 +51,7 @@
# Verify Document Count
- do:
search:
index: test
body: {
query: {
match_all: {}
Expand All @@ -68,3 +66,267 @@
- do:
indices.delete:
index: test

---
"Queries":
- skip:
version: " - 2.99.99"
reason: "rangeQuery and regexpQuery are supported in 3.0.0 in main branch"

- do:
indices.create:
index: test1
body:
mappings:
properties:
genre:
type: "constant_keyword"
value: "d3efault"

# Index documents to test query.
- do:
index:
index: test1
id: 1
body: {
"genre": "d3efault"
}

# Refresh
- do:
indices.refresh:
index: test1

# Test rangeQuery
- do:
search:
index: test1
body: {
query: {
range: {
genre: {
gte: "d3efault"
}
}
}
}

- length: { hits.hits: 1 }

- do:
search:
index: test1
body: {
query: {
range: {
genre: {
from: "d3efault",
"include_lower": "false"
}
}
}
}

- length: { hits.hits: 0 }

- do:
search:
index: test1
body: {
query: {
range: {
genre: {
lte: "d3efault"
}
}
}
}

- length: { hits.hits: 1 }

- do:
search:
index: test1
body: {
query: {
range: {
genre: {
to: "d3efault",
include_upper: "false"
}
}
}
}

- length: { hits.hits: 0 }

- do:
search:
index: test1
body: {
query: {
range: {
genre: {
from: "d3efault",
to: "d3efault",
include_lower: "false",
include_upper: "true"
}
}
}
}

- length: { hits.hits: 0 }

- do:
search:
index: test1
body: {
query: {
range: {
genre: {
from: "d3efault",
to: "d3efault",
include_lower: "true",
include_upper: "false"
}
}
}
}

- length: { hits.hits: 0 }

- do:
search:
index: test1
body: {
query: {
range: {
genre: {
from: null,
to: null
}
}
}
}

- length: { hits.hits: 1 }

- do:
search:
index: test1
body: {
query: {
range: {
genre: {
from: "d3efault",
to: "d3efault",
include_lower: "true",
include_upper: "true"
}
}
}
}

- length: { hits.hits: 1 }

- do:
search:
index: test1
body: {
query: {
range: {
genre: {
from: "d3efaul",
to: "d3efault1",
include_lower: "true",
include_upper: "true"
}
}
}
}

- length: { hits.hits: 1 }

# Test regexpQuery
- do:
search:
index: test1
body: {
query: {
regexp: {
"genre":"d.*"
}
}
}

- length: { hits.hits: 1 }

- do:
search:
index: test1
body: {
query: {
regexp: {
"genre":"d\\defau[a-z]?t"
}
}
}

- length: { hits.hits: 1 }

- do:
search:
index: test1
body: {
query: {
regexp: {
"genre":"d\\defa[a-z]?t"
}
}
}

- length: { hits.hits: 0 }

- do:
search:
index: test1
body: {
query: {
regexp: {
"genre":"d3efa[a-z]{3,3}"
}
}
}

- length: { hits.hits: 1 }

- do:
search:
index: test1
body: {
query: {
regexp: {
"genre":"d3efa[a-z]{4,4}"
}
}
}

- length: { hits.hits: 0 }

- do:
search:
index: test1
body: {
query: {
match_all: {}
}
}

- length: { hits.hits: 1 }
- match: { hits.hits.0._source.genre: "d3efault" }

# Delete Index when connection is teardown
- do:
indices.delete:
index: test1
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public final boolean isAggregatable() {
*/
protected abstract boolean matches(String pattern, boolean caseInsensitive, QueryShardContext context);

private static String valueToString(Object value) {
static String valueToString(Object value) {
return value instanceof BytesRef ? ((BytesRef) value).utf8ToString() : value.toString();
}

Expand Down
Loading
Loading