-
Notifications
You must be signed in to change notification settings - Fork 24.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow to sort search results by VERSION value returned by Painless sc…
…ript (#85990) Version field types have specific semantics in terms of ordering, ie. SemVer. This fix adds a new "version" type for script sorting (in addition to the existing "number" and "string" options) to specify SemVer ordering semantics.
- Loading branch information
1 parent
c453250
commit cd721b8
Showing
14 changed files
with
444 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
pr: 85990 | ||
summary: Allow to sort by script value using `SemVer` semantics | ||
area: Infra/Scripting | ||
type: bug | ||
issues: | ||
- 85989 | ||
- 82287 |
18 changes: 18 additions & 0 deletions
18
.../src/main/resources/org/elasticsearch/painless/org.elasticsearch.script.bytesref_sort.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# | ||
# Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
# or more contributor license agreements. Licensed under the Elastic License | ||
# 2.0 and the Server Side Public License, v 1; you may not use this file except | ||
# in compliance with, at your election, the Elastic License 2.0 or the Server | ||
# Side Public License, v 1. | ||
# | ||
|
||
# The whitelist for the fields api | ||
# The scripts must be whitelisted for painless to find the classes for the field API | ||
|
||
class org.elasticsearch.script.BytesRefProducer @no_import { | ||
} | ||
|
||
class org.elasticsearch.script.BytesRefSortScript @no_import { | ||
} | ||
class org.elasticsearch.script.BytesRefSortScript$Factory @no_import { | ||
} |
20 changes: 20 additions & 0 deletions
20
server/src/main/java/org/elasticsearch/script/BytesRefProducer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
package org.elasticsearch.script; | ||
|
||
import org.apache.lucene.util.BytesRef; | ||
|
||
/** | ||
* used by {@link org.elasticsearch.search.sort.ScriptSortBuilder} to refer to classes in x-pack | ||
* (eg. org.elasticsearch.xpack.versionfield.Version) that need a custom FieldComparatorSource | ||
*/ | ||
public interface BytesRefProducer { | ||
|
||
BytesRef toBytesRef(); | ||
} |
38 changes: 38 additions & 0 deletions
38
server/src/main/java/org/elasticsearch/script/BytesRefSortScript.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
package org.elasticsearch.script; | ||
|
||
import java.io.IOException; | ||
import java.util.Map; | ||
|
||
public abstract class BytesRefSortScript extends AbstractSortScript { | ||
|
||
public static final String[] PARAMETERS = {}; | ||
|
||
public static final ScriptContext<Factory> CONTEXT = new ScriptContext<>("bytesref_sort", Factory.class); | ||
|
||
public BytesRefSortScript(Map<String, Object> params, DocReader docReader) { | ||
super(params, docReader); | ||
} | ||
|
||
public abstract Object execute(); | ||
|
||
/** | ||
* A factory to construct {@link BytesRefSortScript} instances. | ||
*/ | ||
public interface LeafFactory { | ||
BytesRefSortScript newInstance(DocReader reader) throws IOException; | ||
} | ||
|
||
/** | ||
* A factory to construct stateful {@link BytesRefSortScript} factories for a specific index. | ||
*/ | ||
public interface Factory extends ScriptFactory { | ||
LeafFactory newFactory(Map<String, Object> params); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.