Query on _search not working for _count


(JP Toto) #1

Hey guys! Hoping you can see what's going on with this more quickly than I
can.

This query:

{"filter":{"and":[{"term":{"SID":"49"}},{"term":{"BI":"true"}},{"term":{"TA":"Tag
Test"}},{"term":{"TY":"2"}},{"query":{"query_string":{"fields":["RE","SU"],"query":""john@test.com"","default_operator":"AND"}}}]}}

Works for _search but not for _count. Thoughts??

Count throws a No query registered for [filter]] error.


(Clinton Gormley) #2

Hiya

{"filter":{"and":[{"term":{"SID":"49"}},{"term":{"BI":"true"}},{"term":{"TA":"Tag Test"}},{"term":{"TY":"2"}},{"query":{"query_string":{"fields":["RE","SU"],"query":""john@test.com"","default_operator":"AND"}}}]}}

Look at the docs for search
http://www.elasticsearch.org/guide/reference/api/search/request-body.html and for count http://www.elasticsearch.org/guide/reference/api/count.html
and you'll soon see the difference

clint


(JP Toto) #3

Thanks, Clint! Yeah I've been checking those as best I can today. I'm a
little new to ES so it's not jumping out at me at the moment :frowning:

On Monday, April 16, 2012 2:14:20 PM UTC-4, Clinton Gormley wrote:

Hiya

{"filter":{"and":[{"term":{"SID":"49"}},{"term":{"BI":"true"}},{"term":{"TA":"Tag
Test"}},{"term":{"TY":"2"}},{"query":{"query_string":{"fields":["RE","SU"],"query":""
john@test.com"","default_operator":"AND"}}}]}}

Look at the docs for search
http://www.elasticsearch.org/guide/reference/api/search/request-body.htmland for count
http://www.elasticsearch.org/guide/reference/api/count.html
and you'll soon see the difference

clint


(Clinton Gormley) #4

On Mon, 2012-04-16 at 11:33 -0700, JP Toto wrote:

Thanks, Clint! Yeah I've been checking those as best I can today. I'm
a little new to ES so it's not jumping out at me at the moment :frowning:

The search API accepts 'query' and 'filter' parameters, eg:

{
query: { match_all: {}
}

The count API accepts a query, eg:
{
match_all: {}
}

Inconsistent, I know... but that's how it is at the moment

clint

On Monday, April 16, 2012 2:14:20 PM UTC-4, Clinton Gormley wrote:
Hiya
>
>
{"filter":{"and":[{"term":{"SID":"49"}},{"term":{"BI":"true"}},{"term":{"TA":"Tag Test"}},{"term":{"TY":"2"}},{"query":{"query_string":{"fields":["RE","SU"],"query":""john@test.com"","default_operator":"AND"}}}]}}

    Look at the docs for search
    http://www.elasticsearch.org/guide/reference/api/search/request-body.html and for count http://www.elasticsearch.org/guide/reference/api/count.html
    and you'll soon see the difference
    
    clint

(JP Toto) #5

Ohhh I see. Gotcha. I appreciate the tip. Just have to figure out how to
rewrite this now for _count. Thanks!

On Monday, April 16, 2012 2:39:57 PM UTC-4, Clinton Gormley wrote:

On Mon, 2012-04-16 at 11:33 -0700, JP Toto wrote:

Thanks, Clint! Yeah I've been checking those as best I can today. I'm
a little new to ES so it's not jumping out at me at the moment :frowning:

The search API accepts 'query' and 'filter' parameters, eg:

{
query: { match_all: {}
}

The count API accepts a query, eg:
{
match_all: {}
}

Inconsistent, I know... but that's how it is at the moment

clint

On Monday, April 16, 2012 2:14:20 PM UTC-4, Clinton Gormley wrote:
Hiya
>
>

{"filter":{"and":[{"term":{"SID":"49"}},{"term":{"BI":"true"}},{"term":{"TA":"Tag
Test"}},{"term":{"TY":"2"}},{"query":{"query_string":{"fields":["RE","SU"],"query":""
john@test.com"","default_operator":"AND"}}}]}}

    Look at the docs for search

http://www.elasticsearch.org/guide/reference/api/search/request-body.htmland for count
http://www.elasticsearch.org/guide/reference/api/count.html

    and you'll soon see the difference
    
    clint

(JP Toto) #6

Clint,

Is it even possible to filter "queries", then, for _count?

On Monday, April 16, 2012 3:05:25 PM UTC-4, JP Toto wrote:

Ohhh I see. Gotcha. I appreciate the tip. Just have to figure out how to
rewrite this now for _count. Thanks!

On Monday, April 16, 2012 2:39:57 PM UTC-4, Clinton Gormley wrote:

On Mon, 2012-04-16 at 11:33 -0700, JP Toto wrote:

Thanks, Clint! Yeah I've been checking those as best I can today. I'm
a little new to ES so it's not jumping out at me at the moment :frowning:

The search API accepts 'query' and 'filter' parameters, eg:

{
query: { match_all: {}
}

The count API accepts a query, eg:
{
match_all: {}
}

Inconsistent, I know... but that's how it is at the moment

clint

On Monday, April 16, 2012 2:14:20 PM UTC-4, Clinton Gormley wrote:
Hiya
>
>

{"filter":{"and":[{"term":{"SID":"49"}},{"term":{"BI":"true"}},{"term":{"TA":"Tag
Test"}},{"term":{"TY":"2"}},{"query":{"query_string":{"fields":["RE","SU"],"query":""
john@test.com"","default_operator":"AND"}}}]}}

    Look at the docs for search

http://www.elasticsearch.org/guide/reference/api/search/request-body.htmland for count
http://www.elasticsearch.org/guide/reference/api/count.html

    and you'll soon see the difference
    
    clint

(Clinton Gormley) #7

On Mon, 2012-04-16 at 12:43 -0700, JP Toto wrote:

Clint,

Is it even possible to filter "queries", then, for _count?

Yes, that's what the filtered query
http://www.elasticsearch.org/guide/reference/query-dsl/filtered-query.html
and the constant score query
http://www.elasticsearch.org/guide/reference/query-dsl/constant-score-query.html
are used for.

The 'filter' param on the search API is used for filtering results AFTER
facets have been calculated. For other uses of filters, it is better to
use the filtered or constant score queries instead.

clint

On Monday, April 16, 2012 3:05:25 PM UTC-4, JP Toto wrote:
Ohhh I see. Gotcha. I appreciate the tip. Just have to figure
out how to rewrite this now for _count. Thanks!

    On Monday, April 16, 2012 2:39:57 PM UTC-4, Clinton Gormley
    wrote:
            On Mon, 2012-04-16 at 11:33 -0700, JP Toto wrote:
            > Thanks, Clint! Yeah I've been checking those as best
            I can today. I'm
            > a little new to ES so it's not jumping out at me at
            the moment :-(
            
            The search API accepts 'query' and 'filter'
            parameters, eg:
            
              {
                query: { match_all: {}
              }
            
            The count API accepts a query, eg:
              {
                match_all: {}
              }
            
            Inconsistent, I know... but that's how it is at the
            moment
            
            clint
            > 
            > On Monday, April 16, 2012 2:14:20 PM UTC-4, Clinton
            Gormley wrote:
            >         Hiya
            >         > 
            >         >
            >
            {"filter":{"and":[{"term":{"SID":"49"}},{"term":{"BI":"true"}},{"term":{"TA":"Tag Test"}},{"term":{"TY":"2"}},{"query":{"query_string":{"fields":["RE","SU"],"query":"\"john@test.com\"","default_operator":"AND"}}}]}}
            >         
            >         Look at the docs for search
            >
            http://www.elasticsearch.org/guide/reference/api/search/request-body.html and for count http://www.elasticsearch.org/guide/reference/api/count.html
            >         and you'll soon see the difference
            >         
            >         clint
            >         

(JP Toto) #8

Thanks so much, Clint! Appreciate your patience :slight_smile:

On Tuesday, April 17, 2012 5:03:07 AM UTC-4, Clinton Gormley wrote:

On Mon, 2012-04-16 at 12:43 -0700, JP Toto wrote:

Clint,

Is it even possible to filter "queries", then, for _count?

Yes, that's what the filtered query
http://www.elasticsearch.org/guide/reference/query-dsl/filtered-query.html
and the constant score query

http://www.elasticsearch.org/guide/reference/query-dsl/constant-score-query.html
are used for.

The 'filter' param on the search API is used for filtering results AFTER
facets have been calculated. For other uses of filters, it is better to
use the filtered or constant score queries instead.

clint

On Monday, April 16, 2012 3:05:25 PM UTC-4, JP Toto wrote:
Ohhh I see. Gotcha. I appreciate the tip. Just have to figure
out how to rewrite this now for _count. Thanks!

    On Monday, April 16, 2012 2:39:57 PM UTC-4, Clinton Gormley
    wrote:
            On Mon, 2012-04-16 at 11:33 -0700, JP Toto wrote:
            > Thanks, Clint! Yeah I've been checking those as best
            I can today. I'm
            > a little new to ES so it's not jumping out at me at
            the moment :-(
            
            The search API accepts 'query' and 'filter'
            parameters, eg:
            
              {
                query: { match_all: {}
              }
            
            The count API accepts a query, eg:
              {
                match_all: {}
              }
            
            Inconsistent, I know... but that's how it is at the
            moment
            
            clint
            > 
            > On Monday, April 16, 2012 2:14:20 PM UTC-4, Clinton
            Gormley wrote:
            >         Hiya
            >         > 
            >         >
            >

{"filter":{"and":[{"term":{"SID":"49"}},{"term":{"BI":"true"}},{"term":{"TA":"Tag
Test"}},{"term":{"TY":"2"}},{"query":{"query_string":{"fields":["RE","SU"],"query":""
john@test.com"","default_operator":"AND"}}}]}}

            >         
            >         Look at the docs for search
            >

http://www.elasticsearch.org/guide/reference/api/search/request-body.htmland for count
http://www.elasticsearch.org/guide/reference/api/count.html

            >         and you'll soon see the difference
            >         
            >         clint
            >         

(Shay Banon) #9

One more thing, you can use search_type set to count in the search request
URI, and execute regular search requests and get back just the count.
Effectively, it will be as performant as the count API.

On Tue, Apr 17, 2012 at 10:24 PM, JP Toto james.p.toto@gmail.com wrote:

Thanks so much, Clint! Appreciate your patience :slight_smile:

On Tuesday, April 17, 2012 5:03:07 AM UTC-4, Clinton Gormley wrote:

On Mon, 2012-04-16 at 12:43 -0700, JP Toto wrote:

Clint,

Is it even possible to filter "queries", then, for _count?

Yes, that's what the filtered query
http://www.elasticsearch.org/guide/reference/query-dsl/
filtered-query.htmlhttp://www.elasticsearch.org/guide/reference/query-dsl/filtered-query.html
and the constant score query
http://www.elasticsearch.org/guide/reference/query-dsl/
constant-score-query.htmlhttp://www.elasticsearch.org/guide/reference/query-dsl/constant-score-query.html
are used for.

The 'filter' param on the search API is used for filtering results AFTER
facets have been calculated. For other uses of filters, it is better to
use the filtered or constant score queries instead.

clint

On Monday, April 16, 2012 3:05:25 PM UTC-4, JP Toto wrote:
Ohhh I see. Gotcha. I appreciate the tip. Just have to figure
out how to rewrite this now for _count. Thanks!

    On Monday, April 16, 2012 2:39:57 PM UTC-4, Clinton Gormley
    wrote:
            On Mon, 2012-04-16 at 11:33 -0700, JP Toto wrote:
            > Thanks, Clint! Yeah I've been checking those as best
            I can today. I'm
            > a little new to ES so it's not jumping out at me at
            the moment :-(

            The search API accepts 'query' and 'filter'
            parameters, eg:

              {
                query: { match_all: {}
              }

            The count API accepts a query, eg:
              {
                match_all: {}
              }

            Inconsistent, I know... but that's how it is at the
            moment

            clint
            >
            > On Monday, April 16, 2012 2:14:20 PM UTC-4, Clinton
            Gormley wrote:
            >         Hiya
            >         >
            >         >
            >
            {"filter":{"and":[{"term":{"**

SID":"49"}},{"term":{"BI":"true"}},{"term":{"TA":"Tag
Test"}},{"term":{"TY":"2"}},{"query":{"query_string":{"
fields":["RE","SU"],"query":"**"john@test.com"","default_

operator":"AND"}}}]}}

            >
            >         Look at the docs for search
            >
            http://www.elasticsearch.org/**

guide/reference/api/search/**request-body.htmlhttp://www.elasticsearch.org/guide/reference/api/search/request-body.htmland for count
http://www.elasticsearch.org/**guide/reference/api/count.htmlhttp://www.elasticsearch.org/guide/reference/api/count.html

            >         and you'll soon see the difference
            >
            >         clint
            >

(system) #10