# Counting the results with setMinScore

**URL:** <https://discuss.elastic.co/t/counting-the-results-with-setminscore/12043>\
**Category:** Elasticsearch\
**Created:** [May 21, 2013, 12:03am UTC](https://discuss.elastic.co/t/counting-the-results-with-setminscore/12043 "2013-05-21T00:03:13Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![David\_Toth](https://avatars.discourse-cdn.com/v4/letter/d/7993a0/32.png) [@David\_Toth](https://discuss.elastic.co/u/David_Toth)\
**Post date:** [May 21, 2013, 12:03am UTC](https://discuss.elastic.co/t/counting-the-results-with-setminscore/12043/1 "2013-05-21T00:03:13Z")

</div>

Is it possible to count the results of similar documents indexed exceeding  
a certain minimal score with more like this query?

Currently I am doing the following which is very inefficient:

public long getCount(MoreLikeThisQueryBuilder mltQueryBuilder, float  
similarityAcceptance) {

```
    SearchResponse response = client.prepareSearch()

            .setQuery(mltQueryBuilder)

            .setMinScore(similarityAcceptance)

            .execute()

            .actionGet();

    return response.hits().totalHits();

```

}

and I would like something like the following:

public long getCount(MoreLikeThisQueryBuilder mltQueryBuilder, float  
similarityAcceptance) {

```
    CountResponse response = client.prepareCount()

            .setQuery(mltQueryBuilder)

            .setMinScore(similarityAcceptance)

            .execute()

            .actionGet();

    return response.count();

```

}

Except that this second method does not take minimum score into  
consideration, it counts all the documents, that is as if  
similarityAcceptance = 0.0f.

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![David\_Toth](https://avatars.discourse-cdn.com/v4/letter/d/7993a0/32.png) [@David\_Toth](https://discuss.elastic.co/u/David_Toth)\
**Post date:** [May 21, 2013, 4:54pm UTC](https://discuss.elastic.co/t/counting-the-results-with-setminscore/12043/2 "2013-05-21T16:54:05Z")

</div>

My friend told me that the functionality I would want is unsupported.

On Monday, 20 May 2013 17:03:13 UTC-7, Dávid Tóth wrote:

> Is it possible to count the results of similar documents indexed exceeding  
> a certain minimal score with more like this query?
> 
> Currently I am doing the following which is very inefficient:
> 
> public long getCount(MoreLikeThisQueryBuilder mltQueryBuilder, float  
> similarityAcceptance) {
> 
> ```
> SearchResponse response = client.prepareSearch()
> 
> .setQuery(mltQueryBuilder)
> 
> .setMinScore(similarityAcceptance)
> 
> .execute()
> 
> .actionGet();
> 
> return response.hits().totalHits();
> 
> ```
> 
> }
> 
> and I would like something like the following:
> 
> public long getCount(MoreLikeThisQueryBuilder mltQueryBuilder, float  
> similarityAcceptance) {
> 
> ```
> CountResponse response = client.prepareCount()
> 
> .setQuery(mltQueryBuilder)
> 
> .setMinScore(similarityAcceptance)
> 
> .execute()
> 
> .actionGet();
> 
> return response.count();
> 
> ```
> 
> }
> 
> Except that this second method does not take minimum score into  
> consideration, it counts all the documents, that is as if  
> similarityAcceptance = 0.0f.

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![Clinton\_Gormley](https://avatars.discourse-cdn.com/v4/letter/c/50afbb/32.png) [@Clinton\_Gormley](https://discuss.elastic.co/u/Clinton_Gormley)\
**Post date:** [May 23, 2013, 9:53am UTC](https://discuss.elastic.co/t/counting-the-results-with-setminscore/12043/3 "2013-05-23T09:53:29Z")

</div>

Hmm, it should be possible using the search API. Set search\_type=count  
[Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/api/search/search-type/) and  
specify a min\_score  
[Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/api/search/min-score.html)

On 21 May 2013 18:54, Dávid Tóth [900102xy@gmail.com](mailto:900102xy@gmail.com) wrote:

> My friend told me that the functionality I would want is unsupported.
> 
> On Monday, 20 May 2013 17:03:13 UTC-7, Dávid Tóth wrote:
> 
> > Is it possible to count the results of similar documents indexed  
> > exceeding a certain minimal score with more like this query?
> > 
> > Currently I am doing the following which is very inefficient:
> > 
> > public long getCount(\*\*MoreLikeThisQueryBuilder mltQueryBuilder, float  
> > similarityAcceptance) {
> > 
> > ```
> > SearchResponse response = client.prepareSearch()
> > 
> > .setQuery(mltQueryBuilder)
> > 
> > .setMinScore(**similarityAcceptance)
> > 
> > .execute()
> > 
> > .actionGet();
> > 
> > return response.hits().totalHits();
> > 
> > ```
> > 
> > }
> > 
> > and I would like something like the following:
> > 
> > public long getCount(\*\*MoreLikeThisQueryBuilder mltQueryBuilder, float  
> > similarityAcceptance) {
> > 
> > ```
> > CountResponse response = client.prepareCount()
> > 
> > .setQuery(mltQueryBuilder)
> > 
> > .setMinScore(**similarityAcceptance)
> > 
> > .execute()
> > 
> > .actionGet();
> > 
> > return response.count();
> > 
> > ```
> > 
> > }
> > 
> > Except that this second method does not take minimum score into  
> > consideration, it counts all the documents, that is as if  
> > similarityAcceptance = 0.0f.
> > 
> > --  
> > You received this message because you are subscribed to the Google Groups  
> > "elasticsearch" group.  
> > To unsubscribe from this group and stop receiving emails from it, send an  
> > email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
> > For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [July 6, 2017, 2:35am UTC](https://discuss.elastic.co/t/counting-the-results-with-setminscore/12043/4 "2017-07-06T02:35:12Z")

</div>


