3

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?

Keith Morris
  • 275
  • 2
  • 9
  • What are the expected hits and what are you actually getting? Another couple of links would be really easy to visualize. :) – Sai Jul 03 '13 at 23:13
  • Can you post your mapping? Also there is no need to have `type: nested` when you only have one object (e.g. your nonprofit field). You only use nested docs when you want to execute a query on a list of subdocs where you want a hit to be when all parts of a query match in ONE subdoc. – ramseykhalaf Jul 05 '13 at 17:37
  • the pastle link is no longer working. – drewish Apr 28 '14 at 21:20

1 Answers1

0

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

Keith Morris
  • 275
  • 2
  • 9