-
Notifications
You must be signed in to change notification settings - Fork 25.2k
Scripted keyword field #58939
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
Scripted keyword field #58939
Changes from all commits
39edc3c
51e8d23
e7fbaab
0f156cb
6166bc1
939e3f7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
/* | ||
* Licensed to Elasticsearch under one or more contributor | ||
* license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright | ||
* ownership. Elasticsearch licenses this file to you under | ||
* the Apache License, Version 2.0 (the "License"); you may | ||
* not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
package org.elasticsearch.index.fielddata; | ||
|
||
import org.elasticsearch.search.lookup.SearchLookup; | ||
|
||
//TODO this is a temporary interface only to avoid changing signature of MappedFieldType#fielddataBuilder | ||
public interface SearchLookupAware { | ||
|
||
void setSearchLookup(SearchLookup searchLookup); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,25 +6,60 @@ | |
|
||
package org.elasticsearch.xpack.runtimefields; | ||
|
||
import org.elasticsearch.client.Client; | ||
import org.elasticsearch.cluster.metadata.IndexNameExpressionResolver; | ||
import org.elasticsearch.cluster.service.ClusterService; | ||
import org.elasticsearch.common.io.stream.NamedWriteableRegistry; | ||
import org.elasticsearch.common.xcontent.NamedXContentRegistry; | ||
import org.elasticsearch.env.Environment; | ||
import org.elasticsearch.env.NodeEnvironment; | ||
import org.elasticsearch.index.mapper.Mapper; | ||
import org.elasticsearch.plugins.MapperPlugin; | ||
import org.elasticsearch.plugins.Plugin; | ||
import org.elasticsearch.plugins.ScriptPlugin; | ||
import org.elasticsearch.repositories.RepositoriesService; | ||
import org.elasticsearch.script.ScriptContext; | ||
import org.elasticsearch.script.ScriptService; | ||
import org.elasticsearch.threadpool.ThreadPool; | ||
import org.elasticsearch.watcher.ResourceWatcherService; | ||
import org.elasticsearch.xpack.runtimefields.mapper.ScriptFieldMapper; | ||
|
||
import java.util.Collection; | ||
import java.util.Collections; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.function.Supplier; | ||
|
||
public final class RuntimeFields extends Plugin implements MapperPlugin, ScriptPlugin { | ||
|
||
private final ScriptFieldMapper.TypeParser scriptTypeParser = new ScriptFieldMapper.TypeParser(); | ||
|
||
@Override | ||
public Map<String, Mapper.TypeParser> getMappers() { | ||
return Collections.emptyMap(); | ||
return Collections.singletonMap(ScriptFieldMapper.CONTENT_TYPE, scriptTypeParser); | ||
} | ||
|
||
@Override | ||
public List<ScriptContext<?>> getContexts() { | ||
return List.of(DoubleScriptFieldScript.CONTEXT, LongScriptFieldScript.CONTEXT, StringScriptFieldScript.CONTEXT); | ||
} | ||
|
||
@Override | ||
public Collection<Object> createComponents( | ||
Client client, | ||
ClusterService clusterService, | ||
ThreadPool threadPool, | ||
ResourceWatcherService resourceWatcherService, | ||
ScriptService scriptService, | ||
NamedXContentRegistry xContentRegistry, | ||
Environment environment, | ||
NodeEnvironment nodeEnvironment, | ||
NamedWriteableRegistry namedWriteableRegistry, | ||
IndexNameExpressionResolver indexNameExpressionResolver, | ||
Supplier<RepositoriesService> repositoriesServiceSupplier | ||
) { | ||
// looks like createComponents gets called after getMappers | ||
this.scriptTypeParser.setScriptService(scriptService); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That is kind of nasty. Not a blocker for the PR, and maybe not a blocker ever, but a little sad! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yea this caught me by surprise. Though it was not hard to work around. |
||
return Collections.emptyList(); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
package org.elasticsearch.xpack.runtimefields.fielddata; | ||
|
||
import org.elasticsearch.index.fielddata.SortingBinaryDocValues; | ||
import org.elasticsearch.xpack.runtimefields.StringScriptFieldScript; | ||
|
||
public final class ScriptBinaryDocValues extends SortingBinaryDocValues { | ||
|
||
private final StringScriptFieldScript script; | ||
private final ScriptBinaryFieldData.ScriptBinaryResult scriptBinaryResult; | ||
|
||
ScriptBinaryDocValues(StringScriptFieldScript script, ScriptBinaryFieldData.ScriptBinaryResult scriptBinaryResult) { | ||
this.script = script; | ||
this.scriptBinaryResult = scriptBinaryResult; | ||
} | ||
|
||
@Override | ||
public boolean advanceExact(int doc) { | ||
script.setDocument(doc); | ||
script.execute(); | ||
|
||
count = scriptBinaryResult.getResult().size(); | ||
if (count == 0) { | ||
grow(); | ||
return false; | ||
} | ||
|
||
int i = 0; | ||
for (String value : scriptBinaryResult.getResult()) { | ||
grow(); | ||
values[i++].copyChars(value); | ||
} | ||
sort(); | ||
return true; | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok with me.