Skip to content
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

IndexWriter loses track of parent field when index is empty #13340

Closed
msokolov opened this issue May 2, 2024 · 4 comments
Closed

IndexWriter loses track of parent field when index is empty #13340

msokolov opened this issue May 2, 2024 · 4 comments
Labels
Milestone

Comments

@msokolov
Copy link
Contributor

msokolov commented May 2, 2024

Description

This test fails with java.lang.IllegalArgumentException: can't add a parent field to an already existing index without a parent field. If you index any documents in the index, using the parent field or no, then the test passes.

public void testParentFieldEmptyIndex() throws IOException {
    try (Directory dir = newMockDirectory()) {
      IndexWriterConfig iwc = new IndexWriterConfig(new MockAnalyzer(random()));
      iwc.setParentField("parent");
      try (IndexWriter writer = new IndexWriter(dir, iwc)) {
        writer.commit();
      }
      IndexWriterConfig iwc2 = new IndexWriterConfig(new MockAnalyzer(random()));
      iwc2.setParentField("parent");
      try (IndexWriter writer = new IndexWriter(dir, iwc2)) {
        writer.commit();
      }
    }
  }

Version and environment details

No response

@msokolov msokolov changed the title IndexWriter loses track of parent field when documents fail to use it IndexWriter loses track of parent field when index is empty May 2, 2024
@msokolov
Copy link
Contributor Author

msokolov commented May 2, 2024

I hope someone who is familiar with this will quickly see the problem - I'm not sure if we (1) maybe fail to write any FieldInfos when the index is empty, but now we must, or (2) fail to notice that the index we just opened has no FieldInfos and therefore can have a parent field added? It makes more sense to me that we should write a FieldInfos for an empty index.

@msokolov
Copy link
Contributor Author

msokolov commented May 2, 2024

I tried removing

    if (leaves.isEmpty()) {                                                                                                                                                                      
      return FieldInfos.EMPTY;                                                                                                                                                                   
    } else                                                                                                                                                                                       

from FieldInfos.getMergedFieldInfos but this didn't fix it -- although it also might be needed?

@msokolov
Copy link
Contributor Author

msokolov commented May 2, 2024

OK, now I see that field infos is part of the segment so we would not have written it. I guess in this case we should explicitly recognize and work around the empty case.

@msokolov
Copy link
Contributor Author

msokolov commented May 3, 2024

@simonw of you get a moment, your perspective would be helpful. Should we be writing index metadata somewhere outside of a segment? Or tweak the hack we have...

@msokolov msokolov added this to the 10.0.0 milestone May 6, 2024
@msokolov msokolov closed this as completed May 6, 2024
benwtrent added a commit that referenced this issue Jun 18, 2024
) (#13483) (#13504)

* gh-13340: Allow adding a parent field to an index with no fields (#13341) (#13483)

* adding 9.11.1 changes

---------

Co-authored-by: Michael Sokolov <[email protected]>
@iverase iverase modified the milestones: 10.0.0, 9.11.1 Jun 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants