Question

I am attempting to construct an ElasticSearch query and am not getting the results I expect. Any help would be really appreciated!

Mapping Details:

I have indexed documents representing volunteer opportunities. Within each opportunity are fields for:

  1. title of the opp,
  2. summary,
  3. approval status, and
  4. privacy setting.

In addition, each opportunity document has:

  1. one nested nonprofit document representing the nonprofit host of the volunteer opportunity,
  2. one or more nested cause documents representing the causes addressed by the opportunity,
  3. zero or more nested skills documents representing the skills needed from volunteers, and
  4. zero or more nested shift documents representing the time periods available for volunteers to sign up for.

Each nested shift document contains, for now, one nested calendarBlock document with start and end datetime fields as well as a field for the maximum number of volunteers that can sign up for that shift.

The Query

The query I am attempting to construct is a filtered query. A query string is passed in from a form on the web. Then, I need to programmatically attach at least three filters to this query:

  1. A terms filter to return only opportunities with "approved" : "y"
  2. A terms filter to return only opportunities with "private" : "n"
  3. A range filter to return only opportunities with at least one shift with a calendarBlock end field that is greater than the current date/time. (IE: Filter out all past shifts.)

The first two filters are working fine. The third one is where I'm stuck. I think the problem might have something to do with the complicated nesting structure. I attempted a nested filter, but I'm not sure if I did this correctly. Also the date fields are actually nested two levels deep. I am still getting results with past shifts when I attempt the query.

What is the proper way to accomplish filtering out all the opportunities with no future shifts scheduled?

Was it helpful?

Solution

My problem had to do with the way I was formatting my datetimes.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top