'How to query where a full set of indexed values are contained within a set of query values

Consider an index of job roles, each role has a minimum set of skill requirements.

[
   {
      "role":"junior_programmer",
      "requirements":[
         "javascript",
         "c#"
      ]
   },
   {
      "role":"senior_programmer",
      "requirements":[
         "javascript",
         "c#",
         "elasticsearch"
      ]
   }
]

I want to construct queries for applicants, that match the applicant's skills with the requirements. The applicant's skills can be a superset of the requirements, but the applicant must have all of the role requirements.

// Example1: jim does not match any of the roles
{
   "applicant_name":"jim",
   "skills":[
      "javascript"
   ]
}
// Example2: mike matches the junior_programmer role, but not the senior_programmer role
{
   "applicant_name":"mike",
   "skills":[
      "javascript",
      "c#",
      "angular"
   ]
}
// Example3: jane matches the junior_programmer role and the senior_programmer role
{
   "applicant_name":"jane",
   "skills":[
      "javascript",
      "c#",
      "angular",
      "elasticsearch"
   ]
}


Solution 1:[1]

One of the ways is using term_set. It is important to know that you need to inform the doc a new field that defines the number of matches for the doc to be returned.

https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-terms-set-query.html

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 andrecoelho.rabbitbr