0
votes

I received an error when I tried to run POST _count .

This is the bodyJSON:

{
                "size" : "1",
                "from" : "0",
                "track_scores": true,
                "sort" : [
                         { "article_id" : "asc" }
                        ],
                "query": {
                         "filtered": {
                         "query": {
                                "query_string" : {

                                   "fields" : ["content", "title"],

                                   "query" : ` + queryEs + `
                                             }
                                         },
                                 "filter": {
                                         "range": {
                                         "article_id" : {

                            "gte": "` + intToString(s.Maxid) + `"
                                                    }
                                             }
                                         }

                     }
            }

}

This is the error:

{"error":{"root_cause":[{"type":"parsing_exception","reason":"request does not support [size]","line":2,"col":10}],"type":"parsing_exception","reason":"request does not support [size]","line":2,"col":10},"status":400}

I wonder if my query is wrong, does anyone know if a made a mistake?

Thanks

2

2 Answers

0
votes

The error says size field is not supported in this request

0
votes

The COUNT API i.e (_count) itself allows us to easily execute a query and get the number of matches for that query so why you want extra size here? See more about count api here.

So to be clear,

If you want to search and get documents from your index with some limit/offset manner try search api with from and size

If you want to execute your search and get the only matched documents count/numbers then use count api and it doesn't support extra size clause with so size =1 doesn't make any effect here, just avoid it when using count api.