java - Solr 不会覆盖 - 重复的 uniqueKey 条目

标签 java solr lucene solrj

我对 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-6096https://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/

相关文章:

elasticsearch - ElasticSearch查询速度慢,并且第一次查询总是花费太多时间

java - 在 Lucene 4.4.0 中搜索词干和精确词

java - 如何在不使用多次返回的情况下返回值

java - 使用代码生成来创建类似的 Java Action 类

java - 如何在没有初始化和特定数量元素的情况下在 Kotlin 中创建对象数组?

search - Solr 条件添加/更新?

java - 对于这个问题,哪个是 Java 中最好的设计模式?

mysql - 使用 mysql FT 或 Sphinx 进行全文搜索

solr - 关于 Solr 的几个问题。交易和实时搜索

solr - 从Solr 3迁移数据