0

Does someone know how to check if a document is well indexed after an update with Solr ?

I've tried to read the response after calling the add() method of SolrServer as below but it doesn't seem to work :

SolrInputDocument doc = new SolrInputDocument();
/*
 * Processing on document to add fields ...
 */
UpdateResponse response = server.add(doc);


if(response.getStatus()==0){
System.out.println("File Added");
}
else{
System.out.println("Error when Adding File");
}

In the javadoc, there is no way to know what returns the add() method. Does it always return 0 ? In this case, what is the best way to check that a file is well indexed after an update ?

Thank

Corentin

Corentin
  • 325
  • 5
  • 21
  • See http://lucene.472066.n3.nabble.com/UpdateResponse-status-codes-td494847.html – arun Jul 03 '13 at 17:58
  • The new doc won't be available for searching until you commit, so if you really want to make sure, commit, then query and check. – arun Jul 03 '13 at 18:01
  • Okay, Perfect it's what I wanted to know ! :) So the query is the only way to check if your documents are really indexed. I was wondering if the add method return a response that I can use to check documents's updates. Thank – Corentin Jul 04 '13 at 07:49

2 Answers2

1

You need to perform a commit to be able to see the documents added.
Add will simply add the document to the Index.
However, the document is still not returned as search result unless you commit.
When you are indexing documents to solr none of the changes (add/delete/update) you make will appear until you run the commit command.

A commit operation makes index changes visible to new search requests.

Also check for Soft commits which will perform in a more performant manner.

Jayendra
  • 52,349
  • 4
  • 80
  • 90
  • Thank for reply. I'll try to request by unique key and to check if my documents are well indexed as arun suggest me. – Corentin Jul 04 '13 at 08:02
1

To add to Jayendra's answers, there might be situations where you might be trying to index existing document again. e.g. to test a different index-time chain of analyzers.

In these cases, you might not be able to deduce if the document was indexed again if no content changes.

In such cases, _version_ field might come to rescue. _version_ field always changes its value when the document is indexed again. Please refer my answer here to know more about _version_ field.

genonymous
  • 1,598
  • 3
  • 18
  • 27