我对 Solr 5.3.1 有疑问。我的架构相当简单。我有一个 uniqueKey,它是字符串形式的“id”。索引、存储和必需的、非多值的。
我首先使用“content_type:document_unfinished”添加文档,然后覆盖相同的文档,具有相同的 id 但另一个 content_type:document。然后该文档在索引中出现两次。同样,唯一的 uniqueKey 是字符串形式的“id”。该 id 最初来自 mysql-index primary int。
而且看起来这种情况不止发生一次:
http://lucene.472066.n3.nabble.com/uniqueKey-not-enforced-td4015086.html
http://lucene.472066.n3.nabble.com/Duplicate-Unique-Key-td4129651.html
在我的例子中,并非索引中的所有文档都是重复的,只是一些。我假设 - 最初 - 当索引中存在相同的 uniqueKey 时,它们会在提交时被覆盖。这似乎不像我预期的那样有效。我不想简单地更新文档中的某些字段,我想用所有子项完全替换它。
一些统计数据:索引中大约有 350k 个文档。主要与 childDocuments 一起使用。文档由“content_type”字段区分。我使用 SolrJ 以这种方式导入它们:
HttpSolrServer server = new HttpSolrServer(url);
server.add(a Collection<SolrInputDocument>);
server.commit();
我总是再次添加包含所有子项的整个文档。没什么特别的。我最终得到了相同 uniqueKey 的重复文档。没有侧注入(inject)。我只运行带有集成 Jetty 的 Solr。我不会“手动”在 Java 中打开 Lucene 索引。
然后我做的是再次删除+插入。这似乎工作了一段时间,但随后在某些情况下开始给出此错误消息:
Parent query yields document which is not matched by parents filter
发生这种情况的文档似乎是完全随机的,似乎只出现了一件事:它发生的地方是一个 childDocument。我没有运行任何特别的东西,基本上是从网站下载 solr 包并使用 bin/solr start
有人有什么想法吗?
编辑 1
我想我找到了问题,这似乎是一个错误?要重现问题:
我将 Solr 5.3.1 下载到 virtualBox 中的 Debian,并使用 bin/solr start 启动它。添加了一个带有基本配置集的新核心。基本配置集没有任何变化,只是复制它并添加了核心。
这导致索引中有两个具有相同 id 的文档:
SolrClient solrClient = new HttpSolrClient("http://192.168.56.102:8983/solr/test1");
SolrInputDocument inputDocument = new SolrInputDocument();
inputDocument.setField("id", "1");
inputDocument.setField("content_type_s", "doc_unfinished");
solrClient.add(inputDocument);
solrClient.commit();
solrClient.close();
solrClient = new HttpSolrClient("http://192.168.56.102:8983/solr/test1");
inputDocument = new SolrInputDocument();
inputDocument.setField("id", "1");
inputDocument.setField("content_type_s", "doc");
SolrInputDocument childDocument = new SolrInputDocument();
childDocument.setField("id","1-1");
childDocument.setField("content_type_s", "subdoc");
inputDocument.addChildDocument(childDocument);
solrClient.add(inputDocument);
solrClient.commit();
solrClient.close();
搜索:
http://192.168.56.102:8983/solr/test1/select?q= %3A&wt=json&indent=true
导致以下输出:
{
"responseHeader": {
"status": 0,
"QTime": 0,
"params": {
"q": "*:*",
"indent": "true",
"wt": "json",
"_": "1450078098465"
}
},
"response": {
"numFound": 3,
"start": 0,
"docs": [
{
"id": "1",
"content_type_s": "doc_unfinished",
"_version_": 1520517084715417600
},
{
"id": "1-1",
"content_type_s": "subdoc"
},
{
"id": "1",
"content_type_s": "doc",
"_version_": 1520517084838101000
}
]
}
}
我做错了什么?
最佳答案
感谢您的反馈!我把它写成答案,否则它太长了。我实际上从邮件列表中收到了相同的回复:
Mikhail Khludnev Hello Sebastian,
Mixing standalone docs and blocks doesn't work. There are a plenty of issues open.
On Wed, Mar 9, 2016 at 3:02 PM, Sebastian Riemer wrote:
Hi,
to actually describe my problem in short, instead of just linking to the test applicaton, using SolrJ I do the following:
1) Create a new document as a parent and commit
SolrInputDocument parentDoc = new SolrInputDocument(); parentDoc.addField("id", "parent_1"); parentDoc.addField("name_s", "Sarah Connor"); parentDoc.addField("blockJoinId", "1"); solrClient.add(parentDoc); solrClient.commit();2) Create a new document with the same unique-id as in 1) with a child document appended
SolrInputDocument parentDocUpdateing = new SolrInputDocument(); parentDocUpdateing.addField("id", "parent_1"); parentDocUpdateing.addField("name_s", "Sarah Connor"); parentDocUpdateing.addField("blockJoinId", "1"); SolrInputDocument childDoc = new SolrInputDocument(); childDoc.addField("id", "child_1"); childDoc.addField("name_s", "John Connor"); childDoc.addField("blockJoinId", "1"); parentDocUpdateing.addChildDocument(childDoc); solrClient.add(parentDocUpdateing); solrClient.commit();3) Results in 2 Documents with id="parent_1" in solr index
Is this normal behaviour? I thought the existing document should be updated instead of generating a new document with same id.
For a full working test application please see orginal message.
Best regards, Sebastian
我认为这是一个已知问题,并且有几张票与此相关,但我很高兴有办法处理它(从一开始就添加子文档)(https://issues.apache.org/jira/browse/SOLR-6096, https://issues.apache.org/jira/browse/SOLR-5211 , https://issues.apache.org/jira/browse/SOLR-7606 )
关于java - Solr 不会覆盖 - 重复的 uniqueKey 条目,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34253178/
我有一个包含模块的模型。我想在模块中覆盖模型的访问器方法。例如:classBlah这显然行不通。有什么想法可以实现吗? 最佳答案 您的代码看起来是正确的。我们正在毫无困难地使用这个确切的模式。如果我没记错的话,Rails使用#method_missing作为属性setter,因此您的模块将优先,阻止ActiveRecord的setter。如果您正在使用ActiveSupport::Concern(参见thisblogpost),那么您的实例方法需要进入一个特殊的模块:classBlah
设置:狂欢ruby1.9.2高线(1.6.13)描述:我已经相当习惯在其他一些项目中使用highline,但已经有几个月没有使用它了。现在,在Ruby1.9.2上全新安装时,它似乎不允许在同一行回答提示。所以以前我会看到类似的东西:require"highline/import"ask"Whatisyourfavoritecolor?"并得到:Whatisyourfavoritecolor?|现在我看到类似的东西:Whatisyourfavoritecolor?|竖线(|)符号是我的终端光标。知道为什么会发生这种变化吗? 最佳答案
我在我的Rails项目中使用Pow和powifygem。现在我尝试升级我的ruby版本(从1.9.3到2.0.0,我使用RVM)当我切换ruby版本、安装所有gem依赖项时,我通过运行railss并访问localhost:3000确保该应用程序正常运行以前,我通过使用pow访问http://my_app.dev来浏览我的应用程序。升级后,由于错误Bundler::RubyVersionMismatch:YourRubyversionis1.9.3,butyourGemfilespecified2.0.0,此url不起作用我尝试过的:重新创建pow应用程序重启pow服务器更新战俘
我真的很习惯使用Ruby编写以下代码:my_hash={}my_hash['test']=1Java中对应的数据结构是什么? 最佳答案 HashMapmap=newHashMap();map.put("test",1);我假设? 关于java-等价于Java中的RubyHash,我们在StackOverflow上找到一个类似的问题: https://stackoverflow.com/questions/22737685/
我在pry中定义了一个函数:to_s,但我无法调用它。这个方法去哪里了,怎么调用?pry(main)>defto_spry(main)*'hello'pry(main)*endpry(main)>to_s=>"main"我的ruby版本是2.1.2看了一些答案和搜索后,我认为我得到了正确的答案:这个方法用在什么地方?在irb或pry中定义方法时,会转到Object.instance_methods[1]pry(main)>defto_s[1]pry(main)*'hello'[1]pry(main)*end=>:to_s[2]pry(main)>defhello[2]pry(main)
在Ruby类中,我重写了三个方法,并且在每个方法中,我基本上做同样的事情:classExampleClassdefconfirmation_required?is_allowed&&superenddefpostpone_email_change?is_allowed&&superenddefreconfirmation_required?is_allowed&&superendend有更简洁的语法吗?如何缩短代码? 最佳答案 如何使用别名?classExampleClassdefconfirmation_required?is_a
我们的git存储库中目前有一个Gemfile。但是,有一个gem我只在我的环境中本地使用(我的团队不使用它)。为了使用它,我必须将它添加到我们的Gemfile中,但每次我checkout到我们的master/dev主分支时,由于与跟踪的gemfile冲突,我必须删除它。我想要的是类似Gemfile.local的东西,它将继承从Gemfile导入的gems,但也允许在那里导入新的gems以供使用只有我的机器。此文件将在.gitignore中被忽略。这可能吗? 最佳答案 设置BUNDLE_GEMFILE环境变量:BUNDLE_GEMFI
我正在尝试使用boilerpipe来自JRuby。我看过guide从JRuby调用Java,并成功地将它与另一个Java包一起使用,但无法弄清楚为什么同样的东西不能用于boilerpipe。我正在尝试基本上从JRuby中执行与此Java等效的操作:URLurl=newURL("http://www.example.com/some-location/index.html");Stringtext=ArticleExtractor.INSTANCE.getText(url);在JRuby中试过这个:require'java'url=java.net.URL.new("http://www
我只想对我一直在思考的这个问题有其他意见,例如我有classuser_controller和classuserclassUserattr_accessor:name,:usernameendclassUserController//dosomethingaboutanythingaboutusersend问题是我的User类中是否应该有逻辑user=User.newuser.do_something(user1)oritshouldbeuser_controller=UserController.newuser_controller.do_something(user1,user2)我
什么是ruby的rack或python的Java的wsgi?还有一个路由库。 最佳答案 来自Python标准PEP333:Bycontrast,althoughJavahasjustasmanywebapplicationframeworksavailable,Java's"servlet"APImakesitpossibleforapplicationswrittenwithanyJavawebapplicationframeworktoruninanywebserverthatsupportstheservletAPI.ht