Elasticsearch exact String match search with multiple range

DoggyFootGuy
1 min readOct 8, 2019

set target field mapping as ‘keyword’

terms query will be rewritten internally to a constant_score query

Kotlin(Spring) Code

Http Json

POST /plans-en_us/_search
{
"query": {
"bool": {
"filter": [
{
"terms": {
"provider.id": [
"FkYJIg9%2FTjiRzUFN%2BVfIag",
"ro7hDWUMRbWuaMPQ0wfkGw"
],
"boost": 1
}
},
{
"range": {
"plan.booking_acceptance.period_start": {
"from": null,
"to": "2019-11-20T00:00:00.000Z",
"include_lower": true,
"include_upper": true,
"boost": 1
}
}
},
{
"range": {
"plan.booking_acceptance.period_end": {
"from": "2019-11-20T00:00:00.000Z",
"to": null,
"include_lower": true,
"include_upper": true,
"boost": 1
}
}
},
{
"range": {
"plan.booking_acceptance.acceptance_start": {
"from": null,
"to": -2000,
"include_lower": true,
"include_upper": true,
"boost": 1
}
}
},
{
"range": {
"plan.booking_acceptance.cutoff_end": {
"from": -2000,
"to": null,
"include_lower": false,
"include_upper": true,
"boost": 1
}
}
},
{
"range": {
"item.max_guest": {
"from": 4,
"to": null,
"include_lower": true,
"include_upper": true,
"boost": 1
}
}
},
{
"range": {
"item.min_guest": {
"from": null,
"to": 4,
"include_lower": true,
"include_upper": true,
"boost": 1
}
}
},
{
"range": {
"item.max_adult": {
"from": 2,
"to": null,
"include_lower": true,
"include_upper": true,
"boost": 1
}
}
},
{
"range": {
"item.min_adult": {
"from": null,
"to": 2,
"include_lower": true,
"include_upper": true,
"boost": 1
}
}
},
{
"range": {
"item.max_children": {
"from": 1,
"to": null,
"include_lower": true,
"include_upper": true,
"boost": 1
}
}
},
{
"range": {
"item.min_children": {
"from": null,
"to": 1,
"include_lower": true,
"include_upper": true,
"boost": 1
}
}
},
{
"range": {
"provider.child_age_to": {
"from": 3,
"to": null,
"include_lower": true,
"include_upper": true,
"boost": 1
}
}
}
],
"adjust_pure_negative": true,
"boost": 1
}
},
"version": false
}

--

--