mirror of https://github.com/apache/lucene.git
SOLR-9565: The name of TemplateUpdateRequestProcessorFactory' is changed to 'template' from 'Template' and the
name of 'AtomicUpdateProcessorFactory' is changed to 'atomic' from 'Atomic'
This commit is contained in:
parent
d953488e93
commit
e1d4ec7987
|
@ -94,6 +94,9 @@ Upgrading from Solr 6.x
|
||||||
|
|
||||||
* TemplateUpdateRequestProcessorFactory uses {} instead of ${} for template
|
* TemplateUpdateRequestProcessorFactory uses {} instead of ${} for template
|
||||||
|
|
||||||
|
* SOLR-9565: The name of TemplateUpdateRequestProcessorFactory' is changed to 'template' from 'Template' and the
|
||||||
|
name of 'AtomicUpdateProcessorFactory' is changed to 'atomic' from 'Atomic'
|
||||||
|
|
||||||
New Features
|
New Features
|
||||||
----------------------
|
----------------------
|
||||||
* SOLR-9857, SOLR-9858: Collect aggregated metrics from nodes and shard leaders in overseer. (ab)
|
* SOLR-9857, SOLR-9858: Collect aggregated metrics from nodes and shard leaders in overseer. (ab)
|
||||||
|
|
|
@ -61,7 +61,8 @@ public class AtomicUpdateProcessorFactory extends UpdateRequestProcessorFactory
|
||||||
private final static Set<String> VALID_OPS = new HashSet<>(Arrays.asList(ADD, INC, REMOVE, SET, REMOVEREGEX));
|
private final static Set<String> VALID_OPS = new HashSet<>(Arrays.asList(ADD, INC, REMOVE, SET, REMOVEREGEX));
|
||||||
|
|
||||||
private final static String VERSION = "_version_";
|
private final static String VERSION = "_version_";
|
||||||
private final static String ATOMIC_FIELD_PREFIX = "Atomic.";
|
public static final String NAME = "atomic";
|
||||||
|
public final static String ATOMIC_FIELD_PREFIX = "atomic.";
|
||||||
private final static int MAX_ATTEMPTS = 5;
|
private final static int MAX_ATTEMPTS = 5;
|
||||||
|
|
||||||
private VersionInfo vinfo;
|
private VersionInfo vinfo;
|
||||||
|
|
|
@ -29,14 +29,12 @@ import org.apache.solr.update.AddUpdateCommand;
|
||||||
* This is deliberately made to support only the add operation
|
* This is deliberately made to support only the add operation
|
||||||
*/
|
*/
|
||||||
public abstract class SimpleUpdateProcessorFactory extends UpdateRequestProcessorFactory {
|
public abstract class SimpleUpdateProcessorFactory extends UpdateRequestProcessorFactory {
|
||||||
protected final String myName; // if classname==XyzUpdateProcessorFactory myName=Xyz
|
private String myName; // if classname==XyzUpdateProcessorFactory myName=Xyz
|
||||||
protected NamedList initArgs = new NamedList();
|
protected NamedList initArgs = new NamedList();
|
||||||
private static ThreadLocal<SolrQueryRequest> REQ = new ThreadLocal<>();
|
private static ThreadLocal<SolrQueryRequest> REQ = new ThreadLocal<>();
|
||||||
|
|
||||||
protected SimpleUpdateProcessorFactory() {
|
protected SimpleUpdateProcessorFactory() {
|
||||||
String simpleName = this.getClass().getSimpleName();
|
|
||||||
int idx = simpleName.indexOf("UpdateProcessorFactory");
|
|
||||||
this.myName = idx == -1 ? simpleName : simpleName.substring(0, idx);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -80,7 +78,17 @@ public abstract class SimpleUpdateProcessorFactory extends UpdateRequestProcesso
|
||||||
}
|
}
|
||||||
|
|
||||||
private String _param(String name) {
|
private String _param(String name) {
|
||||||
return myName + "." + name;
|
return getMyName() + "." + name;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected String getMyName() {
|
||||||
|
String myName = this.myName;
|
||||||
|
if (myName == null) {
|
||||||
|
String simpleName = this.getClass().getSimpleName();
|
||||||
|
int idx = simpleName.indexOf("UpdateProcessorFactory");
|
||||||
|
this.myName = myName = idx == -1 ? simpleName : simpleName.substring(0, idx);
|
||||||
|
}
|
||||||
|
return myName;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -41,6 +41,7 @@ import org.apache.solr.util.ConcurrentLRUCache;
|
||||||
*/
|
*/
|
||||||
public class TemplateUpdateProcessorFactory extends SimpleUpdateProcessorFactory {
|
public class TemplateUpdateProcessorFactory extends SimpleUpdateProcessorFactory {
|
||||||
private Cache<String, Resolved> templateCache = new ConcurrentLRUCache<>(1000, 800, 900, 10, false, false, null);
|
private Cache<String, Resolved> templateCache = new ConcurrentLRUCache<>(1000, 800, 900, 10, false, false, null);
|
||||||
|
public static final String NAME = "template";
|
||||||
@Override
|
@Override
|
||||||
protected void process(AddUpdateCommand cmd, SolrQueryRequest req, SolrQueryResponse rsp) {
|
protected void process(AddUpdateCommand cmd, SolrQueryRequest req, SolrQueryResponse rsp) {
|
||||||
String[] vals = getParams("field");
|
String[] vals = getParams("field");
|
||||||
|
@ -63,6 +64,10 @@ public class TemplateUpdateProcessorFactory extends SimpleUpdateProcessorFactory
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected String getMyName() {
|
||||||
|
return NAME;
|
||||||
|
}
|
||||||
|
|
||||||
public static Resolved getResolved(String template, Cache<String, Resolved> cache, Pattern pattern) {
|
public static Resolved getResolved(String template, Cache<String, Resolved> cache, Pattern pattern) {
|
||||||
Resolved r = cache == null ? null : cache.get(template);
|
Resolved r = cache == null ? null : cache.get(template);
|
||||||
|
|
|
@ -21,8 +21,10 @@ import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
|
||||||
|
import com.google.common.collect.ImmutableMap;
|
||||||
import org.apache.solr.common.SolrException;
|
import org.apache.solr.common.SolrException;
|
||||||
import org.apache.solr.common.params.MapSolrParams;
|
import org.apache.solr.common.params.MapSolrParams;
|
||||||
import org.apache.solr.common.params.SolrParams;
|
import org.apache.solr.common.params.SolrParams;
|
||||||
|
@ -271,12 +273,13 @@ public final class UpdateRequestProcessorChain implements PluginInfoInitialized
|
||||||
if (s.isEmpty()) continue;
|
if (s.isEmpty()) continue;
|
||||||
UpdateRequestProcessorFactory p = core.getUpdateProcessors().get(s);
|
UpdateRequestProcessorFactory p = core.getUpdateProcessors().get(s);
|
||||||
if (p == null) {
|
if (p == null) {
|
||||||
PluginInfo pluginInfo = new PluginInfo("updateProcessor",
|
Class<UpdateRequestProcessorFactory> factoryClass = implicits.get(s);
|
||||||
Utils.makeMap("name", s,
|
if(factoryClass != null) {
|
||||||
"class", s + "UpdateProcessorFactory",
|
PluginInfo pluginInfo = new PluginInfo("updateProcessor",
|
||||||
"runtimeLib", "true"));
|
Utils.makeMap("name", s,
|
||||||
|
"class", factoryClass.getName()));
|
||||||
core.getUpdateProcessors().put(s, p = core.getUpdateProcessors().createPlugin(pluginInfo).get());
|
core.getUpdateProcessors().put(s, p = core.getUpdateProcessors().createPlugin(pluginInfo).get());
|
||||||
|
}
|
||||||
if (p == null)
|
if (p == null)
|
||||||
throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, "No such processor " + s);
|
throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, "No such processor " + s);
|
||||||
}
|
}
|
||||||
|
@ -315,4 +318,9 @@ public final class UpdateRequestProcessorChain implements PluginInfoInitialized
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static final Map<String, Class> implicits = new ImmutableMap.Builder()
|
||||||
|
.put(TemplateUpdateProcessorFactory.NAME, TemplateUpdateProcessorFactory.class)
|
||||||
|
.put(AtomicUpdateProcessorFactory.NAME, AtomicUpdateProcessorFactory.class)
|
||||||
|
.build();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -45,7 +45,7 @@ public class AtomicUpdateProcessorFactoryTest extends SolrTestCaseJ4 {
|
||||||
AddUpdateCommand cmd = new AddUpdateCommand(new LocalSolrQueryRequest(h.getCore(),
|
AddUpdateCommand cmd = new AddUpdateCommand(new LocalSolrQueryRequest(h.getCore(),
|
||||||
new ModifiableSolrParams()
|
new ModifiableSolrParams()
|
||||||
.add("processor", "Atomic")
|
.add("processor", "Atomic")
|
||||||
.add("Atomic.cat", "delete")
|
.add("atomic.cat", "delete")
|
||||||
.add("commit","true")
|
.add("commit","true")
|
||||||
));
|
));
|
||||||
|
|
||||||
|
@ -63,8 +63,8 @@ public class AtomicUpdateProcessorFactoryTest extends SolrTestCaseJ4 {
|
||||||
public void testNoUniqueIdPassed() throws Exception { //TODO
|
public void testNoUniqueIdPassed() throws Exception { //TODO
|
||||||
AddUpdateCommand cmd = new AddUpdateCommand(new LocalSolrQueryRequest(h.getCore(),
|
AddUpdateCommand cmd = new AddUpdateCommand(new LocalSolrQueryRequest(h.getCore(),
|
||||||
new ModifiableSolrParams()
|
new ModifiableSolrParams()
|
||||||
.add("processor", "Atomic")
|
.add("processor", "atomic")
|
||||||
.add("Atomic.cat", "add")
|
.add("atomic.cat", "add")
|
||||||
.add("commit","true")
|
.add("commit","true")
|
||||||
));
|
));
|
||||||
|
|
||||||
|
@ -85,12 +85,12 @@ public class AtomicUpdateProcessorFactoryTest extends SolrTestCaseJ4 {
|
||||||
|
|
||||||
AddUpdateCommand cmd = new AddUpdateCommand(new LocalSolrQueryRequest(h.getCore(),
|
AddUpdateCommand cmd = new AddUpdateCommand(new LocalSolrQueryRequest(h.getCore(),
|
||||||
new ModifiableSolrParams()
|
new ModifiableSolrParams()
|
||||||
.add("processor", "Atomic")
|
.add("processor", "atomic")
|
||||||
.add("Atomic.cat", "add")
|
.add("atomic.cat", "add")
|
||||||
.add("Atomic.title", "set")
|
.add("atomic.title", "set")
|
||||||
.add("Atomic.count_i", "set")
|
.add("atomic.count_i", "set")
|
||||||
.add("Atomic.name_s", "set")
|
.add("atomic.name_s", "set")
|
||||||
.add("Atomic.multiDefault", "set")
|
.add("atomic.multiDefault", "set")
|
||||||
.add("commit","true")
|
.add("commit","true")
|
||||||
));
|
));
|
||||||
|
|
||||||
|
@ -136,12 +136,12 @@ public class AtomicUpdateProcessorFactoryTest extends SolrTestCaseJ4 {
|
||||||
|
|
||||||
cmd = new AddUpdateCommand(new LocalSolrQueryRequest(h.getCore(),
|
cmd = new AddUpdateCommand(new LocalSolrQueryRequest(h.getCore(),
|
||||||
new ModifiableSolrParams()
|
new ModifiableSolrParams()
|
||||||
.add("processor", "Atomic")
|
.add("processor", "atomic")
|
||||||
.add("Atomic.cat", "add")
|
.add("atomic.cat", "add")
|
||||||
.add("Atomic.title", "set")
|
.add("atomic.title", "set")
|
||||||
.add("Atomic.count_i", "inc")
|
.add("atomic.count_i", "inc")
|
||||||
.add("Atomic.name_s", "remove")
|
.add("atomic.name_s", "remove")
|
||||||
.add("Atomic.multiDefault", "removeregex")
|
.add("atomic.multiDefault", "removeregex")
|
||||||
.add("commit","true")
|
.add("commit","true")
|
||||||
));
|
));
|
||||||
|
|
||||||
|
@ -216,9 +216,9 @@ public class AtomicUpdateProcessorFactoryTest extends SolrTestCaseJ4 {
|
||||||
public void run() {
|
public void run() {
|
||||||
AddUpdateCommand cmd = new AddUpdateCommand(new LocalSolrQueryRequest(h.getCore(),
|
AddUpdateCommand cmd = new AddUpdateCommand(new LocalSolrQueryRequest(h.getCore(),
|
||||||
new ModifiableSolrParams()
|
new ModifiableSolrParams()
|
||||||
.add("processor", "Atomic")
|
.add("processor", "atomic")
|
||||||
.add("Atomic.cat", "add")
|
.add("atomic.cat", "add")
|
||||||
.add("Atomic.int_i", "inc")
|
.add("atomic.int_i", "inc")
|
||||||
.add("commit","true")
|
.add("commit","true")
|
||||||
|
|
||||||
));
|
));
|
||||||
|
|
|
@ -61,10 +61,10 @@ public class TemplateUpdateProcessorTest extends SolrCloudTestCase {
|
||||||
public void testSimple() throws Exception {
|
public void testSimple() throws Exception {
|
||||||
|
|
||||||
ModifiableSolrParams params = new ModifiableSolrParams()
|
ModifiableSolrParams params = new ModifiableSolrParams()
|
||||||
.add("processor", "Template")
|
.add("processor", "template")
|
||||||
.add("Template.field", "id:{firstName}_{lastName}")
|
.add("template.field", "id:{firstName}_{lastName}")
|
||||||
.add("Template.field", "another:{lastName}_{firstName}")
|
.add("template.field", "another:{lastName}_{firstName}")
|
||||||
.add("Template.field", "missing:{lastName}_{unKnown}");
|
.add("template.field", "missing:{lastName}_{unKnown}");
|
||||||
AddUpdateCommand cmd = new AddUpdateCommand(new LocalSolrQueryRequest(null,
|
AddUpdateCommand cmd = new AddUpdateCommand(new LocalSolrQueryRequest(null,
|
||||||
params
|
params
|
||||||
|
|
||||||
|
@ -82,9 +82,9 @@ public class TemplateUpdateProcessorTest extends SolrCloudTestCase {
|
||||||
solrDoc.addField("id", "1");
|
solrDoc.addField("id", "1");
|
||||||
|
|
||||||
params = new ModifiableSolrParams()
|
params = new ModifiableSolrParams()
|
||||||
.add("processor", "Template")
|
.add("processor", "template")
|
||||||
.add("commit", "true")
|
.add("commit", "true")
|
||||||
.add("Template.field", "x_s:key_{id}");
|
.add("template.field", "x_s:key_{id}");
|
||||||
params.add("commit", "true");
|
params.add("commit", "true");
|
||||||
UpdateRequest add = new UpdateRequest().add(solrDoc);
|
UpdateRequest add = new UpdateRequest().add(solrDoc);
|
||||||
add.setParams(params);
|
add.setParams(params);
|
||||||
|
|
|
@ -386,27 +386,27 @@ These Update processors do not need any configuration is your `solrconfig.xml` .
|
||||||
|
|
||||||
The `TemplateUpdateProcessorFactory` can be used to add new fields to documents based on a template pattern.
|
The `TemplateUpdateProcessorFactory` can be used to add new fields to documents based on a template pattern.
|
||||||
|
|
||||||
Use the parameter `processor=Template` to use it. The template parameter `Template.field` (multivalued) defines the field to add and the pattern. Templates may contain placeholders which refer to other fields in the document. You can have multiple `Template.field` parameters in a single request.
|
Use the parameter `processor=template` to use it. The template parameter `template.field` (multivalued) define the field to add and the pattern. Templates may contain placeholders which refer to other fields in the document. You can have multiple `Template.field` parameters in a single request.
|
||||||
|
|
||||||
For example:
|
For example:
|
||||||
|
|
||||||
[source,bash]
|
[source,bash]
|
||||||
----
|
----
|
||||||
processor=Template&Template.field=fullName:Mr. {firstName} {lastName}
|
processor=template&template.field=fullName:Mr. {firstName} {lastName}
|
||||||
----
|
----
|
||||||
|
|
||||||
The above example would add a new field to the document called `fullName`. The fields `firstName` and `lastName` are supplied from the document fields. If either of them is missing, that part is replaced with an empty string. If those fields are multi-valued, only the first value is used.
|
The above example would add a new field to the document called `fullName`. The fields `firstName and` `lastName` are supplied from the document fields. If either of them is missing, that part is replaced with an empty string. If those fields are multi-valued, only the first value is used.
|
||||||
|
|
||||||
==== AtomicUpdateProcessorFactory
|
==== AtomicUpdateProcessorFactory
|
||||||
|
|
||||||
|
|
||||||
Use it to convert your normal `update` operations to atomic update operations. This is particularly useful when you use endpoints such as `/update/csv` or `/update/json/docs` which does not support syntax for atomic operations.
|
Name of the processor is `atomic` . Use it to convert your normal `update` operations to atomic update operations. This is particularly useful when you use endpoints such as `/update/csv` or `/update/json/docs` which does not support syntax for atomic operations.
|
||||||
|
|
||||||
example:
|
example:
|
||||||
|
|
||||||
[source,bash]
|
[source,bash]
|
||||||
----
|
----
|
||||||
processor=Atomic&Atomic.field1=add&Atomic.field2=set&Atomic.field3=inc&Atomic.field4=remove&Atomic.field4=remove
|
processor=atomic&atomic.field1=add&atomic.field2=set&atomic.field3=inc&atomic.field4=remove&atomic.field4=remove
|
||||||
----
|
----
|
||||||
|
|
||||||
The above parameters convert a normal `update` operation on
|
The above parameters convert a normal `update` operation on
|
||||||
|
|
Loading…
Reference in New Issue