You are viewing a plain text version of this content. The canonical link for it is here.
Posted to solr-user@lucene.apache.org by Joe <jo...@gmail.com> on 2012/12/20 07:17:39 UTC

Finding the last committed record in SOLR 4

I'm using SOLR 4 for an application, where I need to search the index soon
after inserting records. 

I'm using the solrj code below to get the last ID in the index. However, I
noticed that the last id I see when I execute a query through the solr web
admin is often lagging behind this. And that my searches are not including
all documents up until the last ID I get from the code snippet below. I'm
guessing this is because of delays in hard commits. I don't need to switch
to soft commits yet. I just want to make sure that I get the ID of the last
searchable document. Is this possible to do?


		 SolrQuery query = new SolrQuery();
		 query.set("qt","/select");
		 query.setQuery( "*:*" );
		 query.setFields("id");
		 query.set("rows","1");
		 query.set("sort","id desc");

		 QueryResponse rsp = m_Server.query( query );
		 SolrDocumentList docs = rsp.getResults();
		 SolrDocument doc = docs.get(0);
		 long id = (Long) doc.getFieldValue("id");
		 



--
View this message in context: http://lucene.472066.n3.nabble.com/Finding-the-last-committed-record-in-SOLR-4-tp4028235.html
Sent from the Solr - User mailing list archive at Nabble.com.

Re: Finding the last committed record in SOLR 4

Posted by Otis Gospodnetic <ot...@gmail.com>.
Hi,

You need to soft commit and then you'll see the latest docs.

Otis
--
Performance Monitoring - http://sematext.com/spm
On Dec 20, 2012 1:18 AM, "Joe" <jo...@gmail.com> wrote:

> I'm using SOLR 4 for an application, where I need to search the index soon
> after inserting records.
>
> I'm using the solrj code below to get the last ID in the index. However, I
> noticed that the last id I see when I execute a query through the solr web
> admin is often lagging behind this. And that my searches are not including
> all documents up until the last ID I get from the code snippet below. I'm
> guessing this is because of delays in hard commits. I don't need to switch
> to soft commits yet. I just want to make sure that I get the ID of the last
> searchable document. Is this possible to do?
>
>
>                  SolrQuery query = new SolrQuery();
>                  query.set("qt","/select");
>                  query.setQuery( "*:*" );
>                  query.setFields("id");
>                  query.set("rows","1");
>                  query.set("sort","id desc");
>
>                  QueryResponse rsp = m_Server.query( query );
>                  SolrDocumentList docs = rsp.getResults();
>                  SolrDocument doc = docs.get(0);
>                  long id = (Long) doc.getFieldValue("id");
>
>
>
>
> --
> View this message in context:
> http://lucene.472066.n3.nabble.com/Finding-the-last-committed-record-in-SOLR-4-tp4028235.html
> Sent from the Solr - User mailing list archive at Nabble.com.
>

Re: Finding the last committed record in SOLR 4

Posted by Joe <jo...@gmail.com>.
Is it possible that some fields (ID, in this case) becomes searchable before
others (the text, in this case)?



--
View this message in context: http://lucene.472066.n3.nabble.com/Finding-the-last-committed-record-in-SOLR-4-tp4028235p4028454.html
Sent from the Solr - User mailing list archive at Nabble.com.

Re: Finding the last committed record in SOLR 4

Posted by Upayavira <uv...@odoko.co.uk>.
I cannot see how SolrJ and the admin UI would return different results.
Could you run exactly the same query on both and show what you get here?

Upayavira

On Thu, Dec 20, 2012, at 06:17 AM, Joe wrote:
> I'm using SOLR 4 for an application, where I need to search the index
> soon
> after inserting records. 
> 
> I'm using the solrj code below to get the last ID in the index. However,
> I
> noticed that the last id I see when I execute a query through the solr
> web
> admin is often lagging behind this. And that my searches are not
> including
> all documents up until the last ID I get from the code snippet below. I'm
> guessing this is because of delays in hard commits. I don't need to
> switch
> to soft commits yet. I just want to make sure that I get the ID of the
> last
> searchable document. Is this possible to do?
> 
> 
> 		 SolrQuery query = new SolrQuery();
> 		 query.set("qt","/select");
> 		 query.setQuery( "*:*" );
> 		 query.setFields("id");
> 		 query.set("rows","1");
> 		 query.set("sort","id desc");
> 
> 		 QueryResponse rsp = m_Server.query( query );
> 		 SolrDocumentList docs = rsp.getResults();
> 		 SolrDocument doc = docs.get(0);
> 		 long id = (Long) doc.getFieldValue("id");
> 		 
> 
> 
> 
> --
> View this message in context:
> http://lucene.472066.n3.nabble.com/Finding-the-last-committed-record-in-SOLR-4-tp4028235.html
> Sent from the Solr - User mailing list archive at Nabble.com.

Re: Finding the last committed record in SOLR 4

Posted by Lance Norskog <go...@gmail.com>.
The only sure way to get the last searchable document is to use a 
timestamp or sequence number in the document. I do not think that using 
a timestamp with default=NOW will give a unique timestamp, so you need 
your own sequence number.

On 12/19/2012 10:17 PM, Joe wrote:
> I'm using SOLR 4 for an application, where I need to search the index soon
> after inserting records.
>
> I'm using the solrj code below to get the last ID in the index. However, I
> noticed that the last id I see when I execute a query through the solr web
> admin is often lagging behind this. And that my searches are not including
> all documents up until the last ID I get from the code snippet below. I'm
> guessing this is because of delays in hard commits. I don't need to switch
> to soft commits yet. I just want to make sure that I get the ID of the last
> searchable document. Is this possible to do?
>
>
> 		 SolrQuery query = new SolrQuery();
> 		 query.set("qt","/select");
> 		 query.setQuery( "*:*" );
> 		 query.setFields("id");
> 		 query.set("rows","1");
> 		 query.set("sort","id desc");
>
> 		 QueryResponse rsp = m_Server.query( query );
> 		 SolrDocumentList docs = rsp.getResults();
> 		 SolrDocument doc = docs.get(0);
> 		 long id = (Long) doc.getFieldValue("id");
> 		
>
>
>
> --
> View this message in context: http://lucene.472066.n3.nabble.com/Finding-the-last-committed-record-in-SOLR-4-tp4028235.html
> Sent from the Solr - User mailing list archive at Nabble.com.