Hello. I'm a newbie in elasticsearch and I have a strange elastic search behaviour. Could someone explain me why belowed query sometimes works and sometimes didnt work? This query should for current date found records. I should mention that in some docs date_from and date_to is equal null (it's mean that doc should be also returned) and I don't want to scoring will rely on on this fields. In result I should get random order of docs without scoring on these date fields (randomScore function has a random int as parameter). This query works for some dates and doesn't work for others.
{
"from": 0,
"size": 12,
"_source": [
"city", "latitude", "description", "title", "id", "lang", "place_id", "longitude", "place_name", "images", "date_to", "subcategory", "date_from", "www"
],
"query": {
"script_score": {
"query": {
"bool": {
"must": {
"bool": {
"must": [
{
"match": {
"lang": "pl"
}
},
{
"bool": {
"should": [
{
"bool": {
"must_not": {
"bool": {
"must": [
{
"exists": {
"field": "date_to"
}
}
]
}
}
}
},
{
"bool": {
"must": [
{
"range": {
"date_to": {
"gte": "2020-02-10"
}
}
},
{
"range": {
"date_from": {
"lte": "2020-02-10"
}
}
}
]
}
}
]
}
}
]
}
}
}
},
"script": {
"source": "randomScore(4298)"
}
}
}
}