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: Range Facet #287

Closed
kimchy opened this issue Aug 1, 2010 · 2 comments
Closed

Search Facets: Range Facet #287

kimchy opened this issue Aug 1, 2010 · 2 comments

Comments

@kimchy
Copy link
Member

kimchy commented Aug 1, 2010

range facet allow to specify a set of ranges and get both the number of docs (count) that fall within each range, and aggregated data either based on the field, or using another field. Here is a simple example:

{
    "query" : {
        "match_all" : {}
    },
    "facets" : {
        "range1" : {
            "range" : {
                "field" : "field_name",
                "ranges" : [
                    { "to" : 50 },
                    { "from" : 20, "to" : 70 }
                    { "from" : 70, "to" : 120 }
                    { "from" : 150 }
                ]
            }
        }
    }
}

Another option which is a bit more DSL enabled is to provide the ranges on the actual field name, for example:

{
    "query" : {
        "match_all" : {}
    },
    "facets" : {
        "range1" : {
            "range" : {
                "my_field" : [
                    { "to" : 50 },
                    { "from" : 20, "to" : 70 }
                    { "from" : 70, "to" : 120 }
                    { "from" : 150 }
                ]
            }
        }
    }
}

Key and Value

The range facet allow to use a different field to check if it doc falls within a range, and another field to compute aggregated data per range (like total). For example:

{
    "query" : {
        "match_all" : {}
    },
    "facets" : {
        "range1" : {
            "range" : {
                "key_field" : "field_name",
                "value_field" : "another_field_name",
                "ranges" : [
                    { "to" : 50 },
                    { "from" : 20, "to" : 70 }
                    { "from" : 70, "to" : 120 }
                    { "from" : 150 }
                ]
            }
        }
    }
}

Script Key and Value

Sometimes, some munging of both the key and the value are needed. In the key case, before it is checked if it falls within a range, and for the value, when the statistical data is computed per range scripts can be used. Here is an example:

{
    "query" : {
        "match_all" : {}
    },
    "facets" : {
        "range1" : {
            "range" : {
                "key_script" : "doc['date'].date.minuteOfHour",
                "value_script" : "doc['num1'].value",
                "ranges" : [
                    { "to" : 50 },
                    { "from" : 20, "to" : 70 }
                    { "from" : 70, "to" : 120 }
                    { "from" : 150 }
                ]
            }
        }
    }
}

Date Ranges

The range facet support also providing the range as string formatted dates.

@kimchy
Copy link
Member Author

kimchy commented Aug 1, 2010

Search Facets: Range Facet, closed by ef861a6.

@EugeneLiang
Copy link

is there an example for range when it is a string formatted date ?

Thanks!

mindw pushed a commit to mindw/elasticsearch that referenced this issue Sep 5, 2022
…quest elastic#287)

Initial terraform for Linode EMS cluster

* Add terraform script to deploy a variable number of EMS servers and one
  redis server in Linode. Servers are protected by linode firewalls
* Deploy a load balancer in front of the EMS servers. Currently at the TCP
  layer because linode does not support HTTPS between LB and nodes
* Some updates to EMS rc.local to support AWS or Linode hosting.
* Add ExecCondition to EMS systemd script to abort if env.sh is not available.
* Also: cleanup installations of awscli apt package - it installs v1, and v2
  installed by provision-common.sh
* Get TLS private key from AWS secrets manager and cert chain from tfvars

Approved-by: Can Yildiz
costin pushed a commit that referenced this issue Dec 6, 2022
…tax (#316)

Resolves #287 

`frm test` now produces

```
org.elasticsearch.xpack.esql.parser.ParsingException: line 1:1: mismatched input 'frm' expecting {'explain', 'from', 'row'}
```

and `from test | filter a > 10` produces

```
org.elasticsearch.xpack.esql.parser.ParsingException: line 1:13: mismatched input 'filter' expecting {'eval', 'stats', 'where', 'sort', 'limit', 'project'}
```

I also noticed that support for comments was somewhat inconsistent and
queries like `from a//comment` or `from a/*comment*/` did not parse.
Supporting single / in the source identifier in from is handy for
supporting unquoted date math expressions as in`from
<my-index-{now/d}>`.
cbuescher pushed a commit to cbuescher/elasticsearch that referenced this issue Oct 2, 2023
emilykmarx pushed a commit to emilykmarx/elasticsearch that referenced this issue Dec 26, 2023
…ed to need to be escaped manually because we stuck it in the URL. Now that it's just in the header we don't need to!

Fixes elastic#287
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