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 ziqi zhang <zi...@gmail.com> on 2018/04/06 20:47:01 UTC

Migrating from Solr 6.6 getStatistics() to Solr 7.x

Hi all

In my Solr 6.6 based code, I have the following line that get the total
number of documents in a collection:

totalDocs=indexSearcher.getStatistics().get("numDocs"))

where indexSearcher is an instance of "SolrIndexSearcher".


With Solr 7.2.1, 'getStatistics' is no longer available, and it seems that
it is replaced by 'collectionStatistics' or 'termStatistics':
https://lucene.apache.org/solr/7_2_1/solr-core/org/apache/solr/search/SolrIndexSearcher.html?is-external=true

So my questions is what is the equivalent statement in solr 7.2.1? Is it:

solrIndexSearcher.collectionStatistics("numDocs").maxDoc();

The API warns that it is still experimental and might change in
incompatible ways in the next release. Is there more 'stable' code for
getting this done?

Thanks

Re: Migrating from Solr 6.6 getStatistics() to Solr 7.x

Posted by ziqi zhang <zi...@gmail.com>.
Thank you!

On Fri, Apr 6, 2018 at 10:34 PM, Chris Hostetter <ho...@fucit.org>
wrote:

>
> : In my Solr 6.6 based code, I have the following line that get the total
> : number of documents in a collection:
> :
> : totalDocs=indexSearcher.getStatistics().get("numDocs"))
>         ...
> : With Solr 7.2.1, 'getStatistics' is no longer available, and it seems
> that
> : it is replaced by 'collectionStatistics' or 'termStatistics':
>         ...
> : So my questions is what is the equivalent statement in solr 7.2.1? Is it:
> :
> : solrIndexSearcher.collectionStatistics("numDocs").maxDoc();
>
> Uh... no.  that's not quite true.
>
> In the 6.x code line, getStatistics() was part of the SolrInfoMBean API
> that SolrIndexSearcher and many other Solr objects implemented...
>
> http://lucene.apache.org/solr/6_6_0/solr-core/org/apache/
> solr/search/SolrIndexSearcher.html#getStatistics--
>
> In 7.0, SolrInfoMBean was replaced with SolrInfoBean as part ofthe switch
> over to the new more robust the Metrics API...
>
> https://lucene.apache.org/solr/guide/7_0/major-changes-
> in-solr-7.html#jmx-support-and-mbeans
> https://lucene.apache.org/solr/guide/7_0/metrics-reporting.html
> http://lucene.apache.org/solr/7_0_0/solr-core/org/apache/
> solr/core/SolrInfoBean.html
>
> (The collectionStatistics() and termStatistics() methods are lower level
> Lucene concepts)
>
> IIRC The closest 7.x equivilent to "indexSearcher.getStatistics()" is
> "indexSearcher.getMetricsSnapshot()" ... but the keys in that map will
> have slightly diff/longer names then they did before, you can use
> "indexSearcher.getMetricNames()" so see the full list.
>
>         ...but frankly that's all a very comlicated way to get "numDocs"
> if you're writting a solr plugin that has direct access to a
> SolrIndexSearcher instance ... you can just call
> "solrIndexSearcher.numDocs()" method and make your life a lot simpler.
>
>
>
> -Hoss
> http://www.lucidworks.com/
>

Re: Migrating from Solr 6.6 getStatistics() to Solr 7.x

Posted by Chris Hostetter <ho...@fucit.org>.
: In my Solr 6.6 based code, I have the following line that get the total
: number of documents in a collection:
: 
: totalDocs=indexSearcher.getStatistics().get("numDocs"))
	... 
: With Solr 7.2.1, 'getStatistics' is no longer available, and it seems that
: it is replaced by 'collectionStatistics' or 'termStatistics':
	...
: So my questions is what is the equivalent statement in solr 7.2.1? Is it:
: 
: solrIndexSearcher.collectionStatistics("numDocs").maxDoc();

Uh... no.  that's not quite true.

In the 6.x code line, getStatistics() was part of the SolrInfoMBean API 
that SolrIndexSearcher and many other Solr objects implemented...

http://lucene.apache.org/solr/6_6_0/solr-core/org/apache/solr/search/SolrIndexSearcher.html#getStatistics--

In 7.0, SolrInfoMBean was replaced with SolrInfoBean as part ofthe switch 
over to the new more robust the Metrics API...

https://lucene.apache.org/solr/guide/7_0/major-changes-in-solr-7.html#jmx-support-and-mbeans
https://lucene.apache.org/solr/guide/7_0/metrics-reporting.html
http://lucene.apache.org/solr/7_0_0/solr-core/org/apache/solr/core/SolrInfoBean.html

(The collectionStatistics() and termStatistics() methods are lower level 
Lucene concepts)

IIRC The closest 7.x equivilent to "indexSearcher.getStatistics()" is 
"indexSearcher.getMetricsSnapshot()" ... but the keys in that map will 
have slightly diff/longer names then they did before, you can use 
"indexSearcher.getMetricNames()" so see the full list.

	...but frankly that's all a very comlicated way to get "numDocs" 
if you're writting a solr plugin that has direct access to a 
SolrIndexSearcher instance ... you can just call 
"solrIndexSearcher.numDocs()" method and make your life a lot simpler.



-Hoss
http://www.lucidworks.com/