My cluster id is cabdbc
Have been trying to write a DSL query, but not able to get it work as expected. I am trying to find those documents, which matched following criteria in my ElasticSearch 2.3 storage and sort high to low score:
-
rents.start
= "2016-09"
AND -
rents.end
= "2016-10"
AND -
rents.abs
is between 200000 and 350000
AND -
los.start
= "2016-09"
AND -
los.max
>= 4
AND -
bedroom_count
>= 2 and <=20<---for more than 2 rooms, per extra room I want to cut (penalize) the relevance score by 8point. E.g. if a document has bedroom_count=5, then score will be reduced by (5-2)*8
AND -
parking
containsstreet
word
I believe from #1 to #6 should be part of filters
while #6 and #7 will be part of the query.
Document mapping is:
{
"properties": {
"bedroom_count": {"type": "integer"},
"parking": {"type": "string"},
"rents": {
"type": "nested",
"dynamic": "strict",
"properties": {
"start": { "type": "date", "format": "yyyy-MM" },
"end": { "type": "date", "format": "yyyy-MM" },
"abs": { "type": "integer" },
},
"los": {
"type": "nested",
"dynamic": "strict",
"properties": {
"start": { "type": "date", "format": "yyyy-MM" },
"max": { "type": "integer" },
"min": { "type": "integer" }
}
}
}
}
A sample doc:
{
"bedroom_count": 4,
"parking": "on the street",
"rents": [
{
"abs": 250000,
"start": "2016-09",
"end": "2016-09"
},
{
"abs": 250000,
"start": "2016-09",
"end": "2016-10"
},
{
"abs": 250000,
"start": "2016-09",
"end": "2016-11"
}
],
"los": [
{
"min": 1,
"max": 12,
"start": "2016-09"
},
{
"min": 1,
"max": 12,
"start": "2016-10"
},
{
"min": 1,
"max": 12,
"start": "2016-11"
}
]
}
And this is what I tried: (please remember filtered
is deprecated in 2.x ref. https://www.elastic.co/blog/better-query-execution-coming-elasticsearch-2-0 )
"query": {
"bool": {
"filter": {
"nested": {
"path": "rents",
"score_mode": "none",
"query": {
"bool": {
"must": [
{
"range": {
"rents.start": {"gte": "2016-09", "lte": "2016-09", }
}
},
{
"range": {
"rents.end": {"gte": "2016-10", "lte": "2016-10", }
}
},
{
"range": {
"rents.abs": {"gte": 200000, "lte": 350000}
}
},
{
"range": {
"los.start": {"gte": "2016-09", "lte": "2016-09"}
}
},
{
"range": {
"los.max": {"gte": 4}
}
}
]
}
}
},
"bool": {
"range": {
"bedroom_count": {
"gte": 2, "lte": 20, "boost": 8
}
}
}
},
"must": [
{
"match": { "parking":"street"}
},
{
"range": {
"bedroom_count": {
"gte": 2, "lte": 20, "boost": 8
}
}
}
]
}
}
As you expected I am doing something wrong here. Hence it is not working at all. Any idea how to modify above query to get it work?
I get this error
{
"error": {
"root_cause": [
{
"type": "parse_exception",
"reason": "Failed to derive xcontent"
}
],
"type": "search_phase_execution_exception",
"reason": "all shards failed",
"phase": "query_fetch",
"grouped": true,
"failed_shards": [
{
"shard": 0,
"index": "listings_v1",
"node": "TopkjPF_S9ueyzpGbF6epg",
"reason": {
"type": "parse_exception",
"reason": "Failed to derive xcontent"
}
}
]
},
"status": 400
}