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

Range queries with elastic4s #450

Closed
ganeshvasudevan opened this issue Oct 1, 2015 · 4 comments
Closed

Range queries with elastic4s #450

ganeshvasudevan opened this issue Oct 1, 2015 · 4 comments

Comments

@ganeshvasudevan
Copy link

Hi,

I was trying to do a range query as explained in the elasticsearch https://www.elastic.co/guide/en/elasticsearch/reference/2.0/query-dsl-range-query.html

The issue is that I dont find a matching DSL in the elastic4s. So my question is how to do date range search in elastic4s?

Should the way forward is to use raw query? I tried with raw query for the date range search and it seems to work but combining that with other query and creating a json dynamically doesnt looks the straightforward way to get it working.

Any help on this issue is greatly appreciated.

thanks and regards
Ganesh

@MLnick
Copy link
Contributor

MLnick commented Oct 1, 2015

You can do a range query or range filter using the DSL:

object RangeQuery extends App {
  import com.sksamuel.elastic4s.ElasticDsl._
  import com.sksamuel.elastic4s.ElasticClient

 val esClient = ElasticClient.local

  // range query
  esClient.execute {
    search in "index" / "type" query {
      rangeQuery("field") from "now-30d" to "now"
    } 
  }

  // range filter
  esClient.execute {
    search in "index" / "type" query {
      filteredQuery query {
        matchall
      } filter {
        rangeFilter("field") from "now-30d" to "now"
      }
    }
  }

}

@ganeshvasudevan
Copy link
Author

Hi,

Thanks a lot, it works as expected.
I will close the issue.

thanks and regards
Ganesh

@sksamuel
Copy link
Collaborator

Do you have a test case I can use to see what's happening?

On 12 December 2015 at 04:21, budzynski notifications@github.com wrote:

It seems like it is broken in the new version 2.1.1 though - I had to use
rawQuery.


Reply to this email directly or view it on GitHub
#450 (comment).

@budzynski
Copy link

Sorry, I thought it was not working but after reading some elastic documentation I finally made it work - it just took me a while to figure out the proper construction. Maybe it was a confusing transition from 1.x APIs. Thanks for your response though.

For all who are looking for some reference - here is how to apply a range filter on time and term filter on symbol value with v. 2.1.1:

search(name) types(name) fields(
"symbol", "bid", "time" ) size(10000) query(
filter( rangeQuery("time") gte(start) lte(end), termQuery("symbol", symbol) ) )

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

4 participants