Skip to content

Commit

Permalink
support rangeQuery and regexpQuery in constant_keyword field type (op…
Browse files Browse the repository at this point in the history
…ensearch-project#14711)


---------

Signed-off-by: kkewwei <[email protected]>
  • Loading branch information
kkewwei authored and akolarkunnu committed Sep 10, 2024
1 parent 0a1607b commit 9102e84
Show file tree
Hide file tree
Showing 5 changed files with 394 additions and 11 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,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 `netty` from 4.1.111.Final to 4.1.112.Final ([#15081](https://github.com/opensearch-project/OpenSearch/pull/15081))
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

0 comments on commit 9102e84

Please sign in to comment.