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

Add field type for version strings #59773

Merged
merged 41 commits into from
Sep 21, 2020
Merged
Show file tree
Hide file tree
Changes from 14 commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
343310c
Add field type for version strings
Jul 14, 2020
397a7c0
Add yaml for search, ranges and scripting
Jul 20, 2020
08989e7
Add brute force regex query support
Jul 22, 2020
8a1acc2
Add fuzzy query support
Jul 23, 2020
bc972ad
Merge branch 'master' into add-version-field
Jul 23, 2020
5bac785
Remove some left-over commented code
Jul 23, 2020
8a7b43c
Adding tests
Jul 23, 2020
910616e
Make string_stats work
Jul 28, 2020
6d71b52
Merge branch 'master' into add-version-field
Jul 28, 2020
970085a
Adressing review comments
Jul 28, 2020
bdb89a2
Remove 'store_malformed' option
Jul 29, 2020
81bb114
Add tests for handling empty string
Jul 29, 2020
5fcf8a7
fix yaml test
Jul 30, 2020
1f3c995
Merge branch 'master' into add-version-field
Jul 30, 2020
cfe2dba
Change range query to points approximation and dv validation
Jul 31, 2020
c70e7c1
Register DocValueFormat via plugin
Jul 31, 2020
e45ef4a
Merge branch 'master' into add-version-field
Aug 17, 2020
24651d1
Merge branch 'master' into add-version-field
Aug 20, 2020
57b040f
Add valueFetcher() method
Aug 20, 2020
c321e0d
Merge branch 'master' of github.com:elastic/elasticsearch into add-ve…
Aug 21, 2020
5b902fb
Restrict field options by moving to ParametrizedFieldMapper
Aug 21, 2020
758b834
Merge branch 'master' into add-version-field
Aug 26, 2020
eaa1ef8
Change range query validation part
Aug 26, 2020
82a40ab
Small improvement to range query using points
Aug 31, 2020
dacf813
Merge branch 'master' into add-version-field
Aug 31, 2020
e4b0728
Add helper methods to versions ScriptDocValues to help with version p…
Sep 2, 2020
3c72862
Merge branch 'master' into add-version-field
Sep 2, 2020
4de9a2e
Merge branch 'master' into add-version-field
Sep 8, 2020
6c3266e
Removing points and subfields
Sep 3, 2020
b26a3f1
Add tests for new regex case-insensitivity option
Sep 8, 2020
c0c39bb
Adding docs
Sep 9, 2020
d56499e
Adressing review comments
Sep 14, 2020
7e2a4f5
Merge branch 'master' into add-version-field
Sep 14, 2020
94def20
Switch script method from isPreRelease to isRelease
Sep 15, 2020
67df1d3
Merge branch 'master' into add-version-field
Sep 15, 2020
ce51484
Another review iteration
Sep 15, 2020
04ac11d
Another round of reviews
Sep 17, 2020
ccebd6f
Moving docs under 'structured'
Sep 17, 2020
b0abc83
Merge branch 'master' into add-version-field
Sep 18, 2020
4c0b1e9
iter
Sep 18, 2020
6849550
Removing specialized script doc values functions
Sep 18, 2020
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
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,10 @@

/** Base {@link MappedFieldType} implementation for a field that is indexed
* with the inverted index. */
abstract class TermBasedFieldType extends SimpleMappedFieldType {
public abstract class TermBasedFieldType extends SimpleMappedFieldType {

TermBasedFieldType(String name, boolean isSearchable, boolean hasDocValues, TextSearchInfo textSearchInfo, Map<String, String> meta) {
public TermBasedFieldType(String name, boolean isSearchable, boolean hasDocValues, TextSearchInfo textSearchInfo,
Map<String, String> meta) {
super(name, isSearchable, hasDocValues, textSearchInfo, meta);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ public void collect(int doc, long bucket) throws IOException {
for (int i = 0; i < valuesCount; i++) {
BytesRef value = values.nextValue();
if (value.length > 0) {
String valueStr = value.utf8ToString();
String valueStr = (String) format.format(value);
int length = valueStr.length();
totalLength.increment(bucket, length);

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
# Integration tests for the version field
#
---
setup:

- skip:
features: headers
version: " - 7.99.99"
reason: "version field is added to 8.0 first"

- do:
indices.create:
index: test_index
body:
mappings:
properties:
version:
type: version

- do:
bulk:
refresh: true
body:
- '{ "index" : { "_index" : "test_index", "_id" : "1" } }'
- '{"version": "1.1.0" }'
- '{ "index" : { "_index" : "test_index", "_id" : "2" } }'
- '{"version": "2.0.0-beta" }'
- '{ "index" : { "_index" : "test_index", "_id" : "3" } }'
- '{"version": "3.1.0" }'

---
"Store malformed":
- do:
indices.create:
index: test_malformed
body:
mappings:
properties:
version:
type: version

- do:
bulk:
refresh: true
body:
- '{ "index" : { "_index" : "test_malformed", "_id" : "1" } }'
- '{"version": "1.1.0" }'
- '{ "index" : { "_index" : "test_malformed", "_id" : "2" } }'
- '{"version": "2.0.0-beta" }'
- '{ "index" : { "_index" : "test_malformed", "_id" : "3" } }'
- '{"version": "v3.1.0" }'
- '{ "index" : { "_index" : "test_malformed", "_id" : "4" } }'
- '{"version": "1.el6" }'

- do:
search:
index: test_malformed
body:
query: { "match" : { "version" : "1.el6" } }

- do:
search:
index: test_malformed
body:
query: { "match_all" : { } }
sort:
version: asc

- match: { hits.total.value: 4 }
- match: { hits.hits.0._source.version: "1.1.0" }
- match: { hits.hits.1._source.version: "2.0.0-beta" }
- match: { hits.hits.2._source.version: "1.el6" }
- match: { hits.hits.3._source.version: "v3.1.0" }

---
"Basic ranges":
- do:
search:
index: test_index
body:
query: { "range" : { "version" : { "gt" : "1.1.0", "lt" : "9999" } } }

- match: { hits.total.value: 2 }

- do:
search:
index: test_index
body:
query: { "range" : { "version" : { "gte" : "1.1.0", "lt" : "9999" } } }

- match: { hits.total.value: 3 }

- do:
search:
index: test_index
body:
query: { "range" : { "version" : { "gte" : "2.0.0", "lt" : "9999" } } }

- match: { hits.total.value: 1 }

- do:
search:
index: test_index
body:
query: { "range" : { "version" : { "gte" : "2.0.0-alpha", "lt" : "9999" } } }

- match: { hits.total.value: 2 }
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# Integration tests for the version field
#
---
setup:

- skip:
features: headers
version: " - 7.99.99"
reason: "version field is added to 8.0 first"

- do:
indices.create:
index: test_index
body:
mappings:
properties:
version:
type: version

- do:
bulk:
refresh: true
body:
- '{ "index" : { "_index" : "test_index", "_id" : "1" } }'
- '{"version": "1.1.12" }'
- '{ "index" : { "_index" : "test_index", "_id" : "2" } }'
- '{"version": "2.0.0-beta" }'
- '{ "index" : { "_index" : "test_index", "_id" : "3" } }'
- '{"version": "3.1.0" }'

---
"Filter script":
- do:
search:
index: test_index
body:
query: { "script" : { "script" : { "source": "doc['version'].value.length() > 5"} } }

- match: { hits.total.value: 2 }
- match: { hits.hits.0._source.version: "1.1.12" }
- match: { hits.hits.1._source.version: "2.0.0-beta" }

---
"Sort script":
- do:
search:
index: test_index
body:
sort: { "_script" : { "type" : "number", "script" : { "source": "doc['version'].value.length()" } } }

- match: { hits.total.value: 3 }
- match: { hits.hits.0._source.version: "3.1.0" }
- match: { hits.hits.1._source.version: "1.1.12" }
- match: { hits.hits.2._source.version: "2.0.0-beta" }
21 changes: 21 additions & 0 deletions x-pack/plugin/versionfield/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
evaluationDependsOn(xpackModule('core'))

apply plugin: 'elasticsearch.esplugin'

esplugin {
name 'versionfield'
description 'A plugin for a field type to store sofware versions'
classname 'org.elasticsearch.xpack.versionfield.VersionFieldPlugin'
extendedPlugins = ['x-pack-core', 'lang-painless']
}
archivesBaseName = 'x-pack-versionfield'

dependencies {
compileOnly project(path: xpackModule('core'), configuration: 'default')
compileOnly project(':modules:lang-painless:spi')
compileOnly project(':modules:lang-painless')
testImplementation project(path: xpackModule('core'), configuration: 'testArtifacts')
testImplementation project(path: xpackModule('analytics'), configuration: 'default')
}

integTest.enabled = false
Loading