Skip to content

Commit

Permalink
Allow parsing on non-string routing fields (elastic#97729)
Browse files Browse the repository at this point in the history
Allow parsing on non-string routing fields

Closes elastic#96552
  • Loading branch information
tmgordeeva authored Oct 3, 2023
1 parent af65bb9 commit 5b2917c
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 0 deletions.
5 changes: 5 additions & 0 deletions docs/changelog/97729.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
pr: 97729
summary: Allow parsing on non-string routing fields
area: Aggregations
type: bug
issues: []
Original file line number Diff line number Diff line change
Expand Up @@ -302,3 +302,39 @@ setup:
mappings:
_source:
enabled: false

---
"Number for keyword routing field":
- skip:
version: " - 8.10.99"
reason: "Fix in 8.11"

- do:
bulk:
index: tsdb
refresh: true
body:
- '{ "index": {} }'
- '{ "key": 10, "val": 1, "@timestamp": "2021-10-01T00:00:10Z" }'
- '{ "index": {}}'
- '{ "key": 11, "val": 2, "@timestamp": "2021-10-01T00:00:00Z" }'

- do:
search:
index: tsdb
body:
query:
range:
"@timestamp":
gte: "2021-10-01T00:00:00Z"
size: 0
aggs:
ts:
time_series:
keyed: false

- match: { hits.total.value: 2 }
- length: { aggregations: 1 }

- match: { aggregations.ts.buckets.0.key: { "key": "10" } }
- match: { aggregations.ts.buckets.0.doc_count: 1 }
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,10 @@ private void extractItem(String path, XContentParser source) throws IOException
case VALUE_NULL:
source.nextToken();
break;
case VALUE_NUMBER: // allow parsing numbers assuming routing fields are always keyword fields
hashes.add(new NameAndHash(new BytesRef(path), hash(new BytesRef(source.text()))));
source.nextToken();
break;
default:
throw new ParsingException(
source.getTokenLocation(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -583,6 +583,16 @@ public void testRoutingPathDotInName() throws IOException {
assertIndexShard(routing, Map.of("foo.bar", "cat", "baz", "dog"), Math.floorMod(hash(List.of("foo.bar", "cat")), shards));
}

public void testRoutingPathNumbersInSource() throws IOException {
int shards = between(2, 1000);
IndexRouting routing = indexRoutingForPath(shards, "foo");
long randomLong = randomLong();
assertIndexShard(routing, Map.of("foo", randomLong), Math.floorMod(hash(List.of("foo", Long.toString(randomLong))), shards));
double randomDouble = randomDouble();
assertIndexShard(routing, Map.of("foo", randomDouble), Math.floorMod(hash(List.of("foo", Double.toString(randomDouble))), shards));
assertIndexShard(routing, Map.of("foo", 123), Math.floorMod(hash(List.of("foo", "123")), shards));
}

public void testRoutingPathBwc() throws IOException {
IndexVersion version = IndexVersionUtils.randomCompatibleVersion(random());
IndexRouting routing = indexRoutingForPath(version, 8, "dim.*,other.*,top");
Expand Down

0 comments on commit 5b2917c

Please sign in to comment.