Skip to content

Commit

Permalink
Merge branch '8.x' into backport/8.x/pr-113183
Browse files Browse the repository at this point in the history
  • Loading branch information
nik9000 committed Sep 24, 2024
2 parents 7e78e51 + cb42fd4 commit c409411
Show file tree
Hide file tree
Showing 110 changed files with 2,477 additions and 478 deletions.
5 changes: 5 additions & 0 deletions docs/changelog/113158.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
pr: 113158
summary: Adds a new Inference API for streaming responses back to the user.
area: Machine Learning
type: enhancement
issues: []
6 changes: 6 additions & 0 deletions docs/changelog/113373.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
pr: 113373
summary: Implement `parseBytesRef` for `TimeSeriesRoutingHashFieldType`
area: TSDB
type: bug
issues:
- 112399
5 changes: 5 additions & 0 deletions docs/changelog/113385.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
pr: 113385
summary: Small performance improvement in h3 library
area: Geo
type: enhancement
issues: []
30 changes: 30 additions & 0 deletions docs/reference/mapping/params/ignore-above.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,33 @@ NOTE: The value for `ignore_above` is the _character count_, but Lucene counts
bytes. If you use UTF-8 text with many non-ASCII characters, you may want to
set the limit to `32766 / 4 = 8191` since UTF-8 characters may occupy at most
4 bytes.

[[index-mapping-ignore-above]]
=== `index.mapping.ignore_above`

The `ignore_above` setting, typically used at the field level, can also be applied at the index level using
`index.mapping.ignore_above`. This setting lets you define a maximum string length for all applicable fields across
the index, including `keyword`, `wildcard`, and keyword values in `flattened` fields. Any values that exceed this
limit will be ignored during indexing and won’t be stored.

This index-wide setting ensures a consistent approach to managing excessively long values. It works the same as the
field-level setting—if a string’s length goes over the specified limit, that string won’t be indexed or stored.
When dealing with arrays, each element is evaluated separately, and only the elements that exceed the limit are ignored.

[source,console]
--------------------------------------------------
PUT my-index-000001
{
"settings": {
"index.mapping.ignore_above": 256
}
}
--------------------------------------------------

In this example, all applicable fields in `my-index-000001` will ignore any strings longer than 256 characters.

TIP: You can override this index-wide setting for specific fields by specifying a custom `ignore_above` value in the
field mapping.

NOTE: Just like the field-level `ignore_above`, this setting only affects indexing and storage. The original values
are still available in the `_source` field if `_source` is enabled, which is the default behavior in Elasticsearch.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ stream or index.
==================================================
Source-only snapshots are only supported if the `_source` field is enabled and no source-filtering is applied.
When you restore a source-only snapshot:
As a result, indices adopting synthetic source cannot be restored. When you restore a source-only snapshot:
* The restored index is read-only and can only serve `match_all` search or scroll requests to enable reindexing.
Expand Down
7 changes: 6 additions & 1 deletion libs/h3/src/main/java/org/elasticsearch/h3/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ final class Constants {
/**
* 2.0 * PI
*/
public static final double M_2PI = 6.28318530717958647692528676655900576839433;
public static final double M_2PI = 2.0 * Math.PI;
/**
* max H3 resolution; H3 version 1 has 16 resolutions, numbered 0 through 15
*/
Expand All @@ -58,6 +58,11 @@ final class Constants {
* square root of 7
*/
public static final double M_SQRT7 = 2.6457513110645905905016157536392604257102;

/**
* 1 / square root of 7
*/
public static final double M_RSQRT7 = 1.0 / M_SQRT7;
/**
* scaling factor from hex2d resolution 0 unit length
* (or distance between adjacent cell center points
Expand Down
11 changes: 7 additions & 4 deletions libs/h3/src/main/java/org/elasticsearch/h3/CoordIJK.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@
*/
final class CoordIJK {

/** one seventh (1/7) **/
private static final double M_ONESEVENTH = 1.0 / 7.0;

/** CoordIJK unit vectors corresponding to the 7 H3 digits.
*/
private static final int[][] UNIT_VECS = {
Expand Down Expand Up @@ -281,8 +284,8 @@ public void neighbor(int digit) {
public void upAp7r() {
final int i = Math.subtractExact(this.i, this.k);
final int j = Math.subtractExact(this.j, this.k);
this.i = (int) Math.round((Math.addExact(Math.multiplyExact(2, i), j)) / 7.0);
this.j = (int) Math.round((Math.subtractExact(Math.multiplyExact(3, j), i)) / 7.0);
this.i = (int) Math.round((Math.addExact(Math.multiplyExact(2, i), j)) * M_ONESEVENTH);
this.j = (int) Math.round((Math.subtractExact(Math.multiplyExact(3, j), i)) * M_ONESEVENTH);
this.k = 0;
ijkNormalize();
}
Expand All @@ -295,8 +298,8 @@ public void upAp7r() {
public void upAp7() {
final int i = Math.subtractExact(this.i, this.k);
final int j = Math.subtractExact(this.j, this.k);
this.i = (int) Math.round((Math.subtractExact(Math.multiplyExact(3, i), j)) / 7.0);
this.j = (int) Math.round((Math.addExact(Math.multiplyExact(2, j), i)) / 7.0);
this.i = (int) Math.round((Math.subtractExact(Math.multiplyExact(3, i), j)) * M_ONESEVENTH);
this.j = (int) Math.round((Math.addExact(Math.multiplyExact(2, j), i)) * M_ONESEVENTH);
this.k = 0;
ijkNormalize();
}
Expand Down
41 changes: 25 additions & 16 deletions libs/h3/src/main/java/org/elasticsearch/h3/FastMath.java
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,15 @@ final class FastMath {
private static final int MIN_DOUBLE_EXPONENT = -1074;
private static final int MAX_DOUBLE_EXPONENT = 1023;

/**
* PI / 2.0
*/
private static final double M_HALF_PI = Math.PI * 0.5;
/**
* PI / 4.0
*/
private static final double M_QUARTER_PI = Math.PI * 0.25;

// --------------------------------------------------------------------------
// CONSTANTS FOR NORMALIZATIONS
// --------------------------------------------------------------------------
Expand Down Expand Up @@ -335,7 +344,7 @@ public static double cos(double angle) {
// Faster than using normalizeZeroTwoPi.
angle = remainderTwoPi(angle);
if (angle < 0.0) {
angle += 2 * Math.PI;
angle += Constants.M_2PI;
}
}
// index: possibly outside tables range.
Expand Down Expand Up @@ -366,7 +375,7 @@ public static double sin(double angle) {
// Faster than using normalizeZeroTwoPi.
angle = remainderTwoPi(angle);
if (angle < 0.0) {
angle += 2 * Math.PI;
angle += Constants.M_2PI;
}
}
int index = (int) (angle * SIN_COS_INDEXER + 0.5);
Expand All @@ -387,9 +396,9 @@ public static double tan(double angle) {
if (Math.abs(angle) > TAN_MAX_VALUE_FOR_INT_MODULO) {
// Faster than using normalizeMinusHalfPiHalfPi.
angle = remainderTwoPi(angle);
if (angle < -Math.PI / 2) {
if (angle < -M_HALF_PI) {
angle += Math.PI;
} else if (angle > Math.PI / 2) {
} else if (angle > M_HALF_PI) {
angle -= Math.PI;
}
}
Expand Down Expand Up @@ -428,7 +437,7 @@ public static double tan(double angle) {
* @return Value arccosine, in radians, in [0,PI].
*/
public static double acos(double value) {
return Math.PI / 2 - FastMath.asin(value);
return M_HALF_PI - FastMath.asin(value);
}

/**
Expand Down Expand Up @@ -468,7 +477,7 @@ public static double asin(double value) {
return negateResult ? -result : result;
} else { // value >= 1.0, or value is NaN
if (value == 1.0) {
return negateResult ? -Math.PI / 2 : Math.PI / 2;
return negateResult ? -M_HALF_PI : M_HALF_PI;
} else {
return Double.NaN;
}
Expand All @@ -490,7 +499,7 @@ public static double atan(double value) {
}
if (value == 1.0) {
// We want "exact" result for 1.0.
return negateResult ? -Math.PI / 4 : Math.PI / 4;
return negateResult ? -M_QUARTER_PI : M_QUARTER_PI;
} else if (value <= ATAN_MAX_VALUE_FOR_TABS) {
int index = (int) (value * ATAN_INDEXER + 0.5);
double delta = value - index * ATAN_DELTA;
Expand All @@ -511,7 +520,7 @@ public static double atan(double value) {
if (Double.isNaN(value)) {
return Double.NaN;
} else {
return negateResult ? -Math.PI / 2 : Math.PI / 2;
return negateResult ? -M_HALF_PI : M_HALF_PI;
}
}
}
Expand All @@ -532,9 +541,9 @@ public static double atan2(double y, double x) {
}
if (x == Double.POSITIVE_INFINITY) {
if (y == Double.POSITIVE_INFINITY) {
return Math.PI / 4;
return M_QUARTER_PI;
} else if (y == Double.NEGATIVE_INFINITY) {
return -Math.PI / 4;
return -M_QUARTER_PI;
} else if (y > 0.0) {
return 0.0;
} else if (y < 0.0) {
Expand All @@ -551,9 +560,9 @@ public static double atan2(double y, double x) {
}
if (x == Double.NEGATIVE_INFINITY) {
if (y == Double.POSITIVE_INFINITY) {
return 3 * Math.PI / 4;
return 3 * M_QUARTER_PI;
} else if (y == Double.NEGATIVE_INFINITY) {
return -3 * Math.PI / 4;
return -3 * M_QUARTER_PI;
} else if (y > 0.0) {
return Math.PI;
} else if (y < 0.0) {
Expand All @@ -562,9 +571,9 @@ public static double atan2(double y, double x) {
return Double.NaN;
}
} else if (y > 0.0) {
return Math.PI / 2 + FastMath.atan(-x / y);
return M_HALF_PI + FastMath.atan(-x / y);
} else if (y < 0.0) {
return -Math.PI / 2 - FastMath.atan(x / y);
return -M_HALF_PI - FastMath.atan(x / y);
} else {
return Double.NaN;
}
Expand All @@ -577,9 +586,9 @@ public static double atan2(double y, double x) {
}
}
if (y > 0.0) {
return Math.PI / 2;
return M_HALF_PI;
} else if (y < 0.0) {
return -Math.PI / 2;
return -M_HALF_PI;
} else {
return Double.NaN;
}
Expand Down
23 changes: 13 additions & 10 deletions libs/h3/src/main/java/org/elasticsearch/h3/Vec2d.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,11 @@
*/
final class Vec2d {

/** sin(60') */
private static final double M_SIN60 = Constants.M_SQRT3_2;
/** 1/sin(60') **/
private static final double M_RSIN60 = 1.0 / Constants.M_SQRT3_2;

/** one third **/
private static final double M_ONETHIRD = 1.0 / 3.0;

private static final double VEC2D_RESOLUTION = 1e-7;

Expand Down Expand Up @@ -133,14 +136,14 @@ static LatLng hex2dToGeo(double x, double y, int face, int res, boolean substrat

// scale for current resolution length u
for (int i = 0; i < res; i++) {
r /= Constants.M_SQRT7;
r *= Constants.M_RSQRT7;
}

// scale accordingly if this is a substrate grid
if (substrate) {
r /= 3.0;
if (H3Index.isResolutionClassIII(res)) {
r /= Constants.M_SQRT7;
r *= Constants.M_RSQRT7;
}
}

Expand Down Expand Up @@ -181,8 +184,8 @@ static CoordIJK hex2dToCoordIJK(double x, double y) {
a2 = Math.abs(y);

// first do a reverse conversion
x2 = a2 / M_SIN60;
x1 = a1 + x2 / 2.0;
x2 = a2 * M_RSIN60;
x1 = a1 + x2 * 0.5;

// check if we have the center of a hex
m1 = (int) x1;
Expand All @@ -193,8 +196,8 @@ static CoordIJK hex2dToCoordIJK(double x, double y) {
r2 = x2 - m2;

if (r1 < 0.5) {
if (r1 < 1.0 / 3.0) {
if (r2 < (1.0 + r1) / 2.0) {
if (r1 < M_ONETHIRD) {
if (r2 < (1.0 + r1) * 0.5) {
i = m1;
j = m2;
} else {
Expand All @@ -215,7 +218,7 @@ static CoordIJK hex2dToCoordIJK(double x, double y) {
}
}
} else {
if (r1 < 2.0 / 3.0) {
if (r1 < 2.0 * M_ONETHIRD) {
if (r2 < (1.0 - r1)) {
j = m2;
} else {
Expand All @@ -228,7 +231,7 @@ static CoordIJK hex2dToCoordIJK(double x, double y) {
i = Math.incrementExact(m1);
}
} else {
if (r2 < (r1 / 2.0)) {
if (r2 < (r1 * 0.5)) {
i = Math.incrementExact(m1);
j = m2;
} else {
Expand Down
2 changes: 1 addition & 1 deletion libs/h3/src/main/java/org/elasticsearch/h3/Vec3d.java
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ static long geoToH3(int res, double lat, double lon) {
}
}
// cos(r) = 1 - 2 * sin^2(r/2) = 1 - 2 * (sqd / 4) = 1 - sqd/2
double r = FastMath.acos(1 - sqd / 2);
double r = FastMath.acos(1 - sqd * 0.5);

if (r < Constants.EPSILON) {
return FaceIJK.faceIjkToH3(res, face, new CoordIJK(0, 0, 0));
Expand Down
Loading

0 comments on commit c409411

Please sign in to comment.