Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Facets not working as per docs #50

Closed
designermonkey opened this issue Mar 5, 2014 · 4 comments
Closed

Facets not working as per docs #50

designermonkey opened this issue Mar 5, 2014 · 4 comments

Comments

@designermonkey
Copy link

If I use:

{
    "query" : {
        "match_all" : {  }
    },
    "facets" : {
        "tag" : {
            "terms" : {
                "field" : "tag",
                "all_terms" : true
            }
        }
    }
}

from the documentation, as a PHP array converted to json by the php-api, the all_terms part doesn't work.

@polyfractal
Copy link
Contributor

Do you mean you are receiving an exception from Elasticsearch, a PHP parse error or just not returning the results that you expect?

Everything appears to be working fine on my end:

$client = new Elasticsearch\Client();

$query = array(
    'query' => array(
        'match_all' => array()
    ),
    'facets' => array(
        'tag' => array(
            'terms' => array(
                'field' => 'tag',
                'all_terms' => true
            )
        )
    )
);
$params['body'] = $query;
$params['index'] = 't';
$params['type'] = 't';
$ret = $client->search($params);

print_r($ret);
Array
(
    [took] => 19
    [timed_out] => 
    [_shards] => Array
        (
            [total] => 5
            [successful] => 5
            [failed] => 0
        )

    [hits] => Array
        (
            [total] => 3
            [max_score] => 1
            [hits] => Array
            ( ... )
        )
    [facets] => Array
        (
            [tag] => Array
                (
                    [_type] => terms
                    [missing] => 1
                    [total] => 6
                    [other] => 0
                    [terms] => Array
                        (
                            [0] => Array
                                (
                                    [term] => z
                                    [count] => 1
                                )
                            [1] => Array
                                (
                                    [term] => y
                                    [count] => 1
                                )
                            [2] => Array
                                (
                                    [term] => x
                                    [count] => 1
                                )
                            [3] => Array
                                (
                                    [term] => c
                                    [count] => 1
                                )
                            [4] => Array
                                (
                                    [term] => b
                                    [count] => 1
                                )
                            [5] => Array
                                (
                                    [term] => a
                                    [count] => 1
                                )
                        )
                )
        )
)

@designermonkey
Copy link
Author

Should have been clearer, was in a rush, sorry.

It still truncates at 10 facet results for me which is the default, when I have 13 possible results.

I'm on ES v1.0

@polyfractal
Copy link
Contributor

Ah, that's just Elasticsearch's behavior.

The all_terms parameter just controls if terms with zero counts show up in the results. The results that are actually returned are still subject to the facet size parameter, which is 10 by default. You need to increase the facet size to get more results back (regardless of their count):

$query = array(
    'query' => array(
        'match_all' => array()
    ),
    'facets' => array(
        'tag' => array(
            'terms' => array(
                'field' => 'tag',
                'all_terms' => true,
                'size' => 200
            )
        )
    )
);

@designermonkey
Copy link
Author

Ahhh, ok, no problem. I have switched it to the size parameter anyway, thanks for clearing that up.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants