Search for availability of resources by dates

Doesn't look like a bad way.

Here's the answer to your other questions on boosting etc:

POST test/doc
{
	"name":"mark",
	"availability":["monday","tuesday"],
	"possible_availability":["friday"]

}
GET test/doc/_search
{
   "query": {
	  "bool": {
		 "should": [
			{
			   "bool": {
				  "should": [
					 {
						"term": {
						   "possible_availability": "monday",
						   "_name": "monday"
						}
					 },
					 {
						"term": {
						   "availability": "monday",
						   "_name": "monday",
						   "boost":2
						}
					 }
				  ]
			   }
			},
			{
			   "bool": {
				  "should": [
					 {
						"term": {
						   "possible_availability": "tuesday",
						   "_name": "tuesday"
						}
					 },
					 {
						"term": {
						   "availability": "tuesday",
						   "_name": "tuesday",
						   "boost":2
						}
					 }
				  ]
			   }
			},            
			{
			   "bool": {
				  "should": [
					 {
						"term": {
						   "possible_availability": "wednesday",
						   "_name": "wednesday"
						}
					 },
					 {
						"term": {
						   "availability": "wednesday",
						   "_name": "wednesday",
						   "boost":2
						}
					 }
				  ]
			   }
			}                        
		 ],
		 "minimum_number_should_match": 2
	  }
   }
}

The usual default ranking heuristics of IDF (how rare a word is) are still in effect here so it would also make sense to wrap each term query in a constant_score query [1].

The use of "_name" in the query provides metadata that is echoed back in each hit to show what matched or not.
For fancier ranking you may want to look at the function_score [2]

Cheers
Mark

[1] Constant score query | Elasticsearch Guide [8.11] | Elastic
[2] Function score query | Elasticsearch Guide [8.11] | Elastic

1 Like