Solr:通过查询部分更新删除值(Solr: remove value with partial update by query)
我想从大索引中的多值字段中删除一个特定值,我需要先查询哪些文档包含该值,即:
- 检索包含特定值的文档的ID。
- 部分更新这些文件(使用
remove
)。Solr版本是5.1。 如有必要,我可以更新,但更改日志并不表示与此问题有任何关联。
我通过Solr Web界面( http:// localhost:8983 / solr /#/ core / documents )在
/select
端点上尝试了以下查询(在一些变体中),尝试从所有文档中删除值:{"id":"*", "field": {"remove":"value"} }
服务器响应“成功”,但没有更新文档。
我可以做的是查询
field:value
,提取文档ID,并(以编程方式)为这些ID生成更新查询,类似于本答案中指出的内容。 但我希望应该有一个更直接的解决方案。部分更新文档和其他相关网页中提供的示例在此处并不真正适用,因为它们假定已事先知道更新文档的ID。 关于类似问题的大多数其他讨论在引入部分更新之前(在Solr 4中)引用旧的Solr版本。
I want to remove one specific value from a multivalued field in a large index, where I need to query first which documents contain that value, i.e.:
- retrieve IDs of the documents containing the specific value.
- partially update these documents (using
remove
).Solr version is 5.1. I could update if necessary, but the change logs do not indicate any relevance to this issue.
I've tried the following query (in a few variations) on the
/select
endpoint through the Solr web interface (http://localhost:8983/solr/#/core/documents), trying to remove the value from all the documents:{"id":"*", "field": {"remove":"value"} }
The server response is "success", but no document is updated.
What I could do is to query for
field:value
, extract the document IDs, and (programmatically) generate update queries for these IDs, similar to what has been indicated in this answer. But I would expect that there should be a more straight-forward solution.The examples presented in the partial updates documentation and other related web pages are not really applicable here because they assume that the ID of the updated documents are known in advance. Most other discussions about similar issues refer to old Solr versions, before partial updates were introduced (in Solr 4).
原文:https://stackoverflow.com/questions/39407091
最满意答案
Minerals
将始终注入Granite
,无论您选择哪种注射技术,但有些注射比其他注射更“清洁” - 例如,选项1使您无法控制注射的完成方式,选项3意味着您的课程可以'是不可改变的。- 如果未绑定
Minerals
,缺少公共无参数构造函数,并且缺少@Inject
构造函数,则Guice会抛出异常,除非您使用@Inject(optional = true)
。
Minerals
will always be injected into theGranite
, whichever injection technique you choose, but some injections are "cleaner" than others -- for example, option 1 gives you less control over how the injection is done, and option 3 means your class can't be immutable.- If
Minerals
isn't bound, lacks a public no-argument constructor, and lacks an@Inject
constructor, then Guice throws an exception, unless you use@Inject(optional = true)
.
相关问答
更多-
Guice可选注射(Optional injection in Guice)[2022-02-07]
我认为首选的Guice模式是这样的: public class HolderPatter { static class Bar { @Inject Bar(BarDependency dependency) {} } static class Baz { @Inject Baz(BazDependency dependency) {} } static class BarHolder { @Inject(optional=true) Bar value = n ... -
您是否尝试在每个构造函数中注入Provider
而不是实际实例? 如果你不需要构造函数代码中的其他实例,那么只需将Provider存储到final字段,稍后再使用该字段(通过调用get() )。 Did you try injecting a Provider in each constructor instead of the actual instances? If you don't need the other instance in the code of constructor, th ... -
我找到的解决方案(如果不是最好的)是定义一个CustomServletContext并使用guice-bridge工件,在jersey问题跟踪器中引用问题HK2-121之后。 解决方案: public class KratosServletContainer extends ServletContainer { private Injector injector; @Inject KratosServletContainer(Injector injector, Resou ...
-
乍一看,你似乎错过了Db注释依赖和StatsdClient的绑定。 你需要像这样提供缺少的绑定到你的模块 bind(Db.class).annotatedWith(SystemDb.class).to(DbImplOfSomeSort.class); bind(StatsdClient.class).to(StatsdClientImplOfSomeSort.class); Guice能够使用公共无参数构造函数或具有@Inject的构造函数自动注入具体类,而无需在模块中定义任何特定的绑定,但涉及到接口时, ...
-
Guice部分注射实例(Guice partial injection example)[2022-06-14]
你是对的,这种注射只能通过使用工厂来解决。 如果你有Foo(A a, B b)注入A并且B在运行时传递,你将需要一个Factory FooFactory.createFoo(B b) ,它在内部保存对A的引用。 幸运的是,Guice有@Assisted Injection的概念。 您必须提供工厂的界面,但可以将实现的“魔力”留给Guice。 它有很好的文档记录: https : //github.com/google/guice/wiki/AssistedInject 您需要额外依赖com.google.i ... -
Minerals将始终注入Granite ,无论您选择哪种注射技术,但有些注射比其他注射更“清洁” - 例如,选项1使您无法控制注射的完成方式,选项3意味着您的课程可以'是不可改变的。 如果未绑定Minerals ,缺少公共无参数构造函数,并且缺少@Inject构造函数,则Guice会抛出异常,除非您使用@Inject(optional = true) 。 Minerals will always be injected into the Granite, whichever injection techn ...
-
看起来“辅助注射”可能是一个解决方案: http://google-guice.googlecode.com/svn/trunk/latest-javadoc/com/google/inject/assistedinject/FactoryModuleBuilder.html 如果您无权访问Foo的构造函数,则它不起作用。 编辑:我发现我可以通过扩展类型并将它们添加到我想要使用的构造函数中来添加辅助注入注释: public class AssistedFoo extends Foo { @Assis ...
-
可以防止Guice将某些对象注入某种类型吗?(Can prevent Guice from injecting some objects into certain type?)[2024-01-12]
您的标题和问题不符。 标题的答案显然是肯定的 - 你还可以注入什么,以及Guice可以创建什么样的实例,如果不是具体的类? 你的问题的答案是你可以通过阻止编译B来防止A注入B,如果它使用A - 通过限制可见性(如public , private ),或者通过构造你的构建以便A不在编译B时的类路径 Your title and question don't match. The answer to the title is yes, obviously - what else can you inject i ... -
Guice按需注射(Guice on-demand injection)[2023-07-27]
如果要使用完全相同的配置实例(类Props),可以将其实例绑定为具有提供程序绑定的单例 。 这当然不是唯一的解决方案,但对我来说这是有道理的。 这是一个例子: 定义提供者: public class PropsProvider implements Provider{ @Override public Props get() { ...read and return Props here... } } 在单例范围内使用提供程序绑定: bind ... -
看看Binder doc: http://google-guice.googlecode.com/git/javadoc/com/google/inject/Binder.html requireExplicitBindings()可能就是你所需要的。 通过使用模块中的语句,禁用自动绑定,仅注入通过bind()或provides类配置的类。 Apparently, the only way to do this is to write a provider method for each prohibite ...