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

Search Facets: Histogram Facet - allow to create buckets with one field name, and aggregate valued on another field #219

Closed
kimchy opened this issue Jun 10, 2010 · 6 comments

Comments

@kimchy
Copy link
Member

kimchy commented Jun 10, 2010

You can created buckets based on one field values (for example, timestamp), and total/count another field from the same doc.

Here is an example:

{
    query : {
        "match_all" : {}
    },
    facets : {
        "histo1" : {
            "histogram" : {
                "key_field" : "fieldX",
                "value_field" : "fieldY",
                "time_interval" : "5d"
            }
        }
    }
}
@kimchy
Copy link
Member Author

kimchy commented Jun 10, 2010

implemented.

@mootpointer
Copy link

What if all I want is the bucketed facets, no aggregation?

@kimchy
Copy link
Member Author

kimchy commented Jun 19, 2010

can you give an example?

@mootpointer
Copy link

So for example I want to know the the count of documents fitting into date buckets.

Eg. I have a document with a created_at field which is a date. I want to know how many have been found each day of the month for the last month, something akin to http://wiki.apache.org/solr/SimpleFacetParameters#Date_Faceting_Parameters

@kimchy
Copy link
Member Author

kimchy commented Jun 20, 2010

The check out #228, it gives you the ability to work within the script on a date object, which has simple constructs to get, for example, the day of month as the key. In order to perform it in the last month, you will need to either execute a filter on the facet, or on the query, depends on the scope of your query (if its already filters by "last month filter).

@kimchy
Copy link
Member Author

kimchy commented Jun 20, 2010

One more thing, you can also define time_interval which is in elasticsearch time format (for example 2d or 1.5h) as the interval. Since dates are represented as millis in the index, this will work.

ClaudioMFreitas pushed a commit to ClaudioMFreitas/elasticsearch-1 that referenced this issue Nov 12, 2019
williamrandolph pushed a commit to williamrandolph/elasticsearch that referenced this issue Jun 4, 2020
close elastic#219

(cherry picked from commit 5a1f1af241d6db36fb39524ac00d86742771c91d)
costin pushed a commit that referenced this issue Dec 6, 2022
Resolves #221

Because ESQL needs to know the context of the current command to correctly parse its structure, command names need to be lexed as individual tokens if they occur in a position where a command name is expected (at the beginning of the query or after a pipe). But if the command name occurs in a different position, it acts as a normal identifier and should be lexed accordingly.

The easiest way to achieve this is to introduce two separate lexer modes. The default mode is used in the command context and the EXPRESSION mode is used when parsing the content of a command (expressions). Another lexer mode in the context of the from command could also be used to address #219.

Unfortunately, lexer modes are only supported if the parser and lexer are split into two separate grammars (not within a combined grammar). I tried to keep the diff caused by this split as minimal as possible but ANTLR does not make this very easy.

Alternatively, one could also allow the command tokens as an alternative for UNQUOTED_IDENTIFIER and then turn it into its string representation in the visitor. This approach is more brittle though as forgetting to add a command as a possible identifier can break existing queries. Additionally, it does not allow alternative lexer modes for commands that accepts arguments other than normal expressions.
costin pushed a commit that referenced this issue Dec 6, 2022
Resolves #219.

Extends the lexer modes introduced in #223 with another mode for commands accepting wildcard identifiers.
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants