Slide 9
Slide 9 text
Copyright Elasticsearch 2013. Copying, publishing and/or distributing without written permission is strictly prohibited
query DSL, take II
$ curl localhost:9200/dba.stackexchange.com/question/_search -d '!
{!
"query": {!
"custom_score": {!
"query": {!
"filtered": {!
"query": {!
"bool": {!
"must": [!
{"multi_match": {"fields": ["title^10", "body"], "query": "mysql"}},!
{!
"has_child": {!
"child_type": "answer",!
"query": {"match": {"body": "nosql"}}!
}!
}!
],!
"must_not": [!
{"multi_match": {"fields": ["title", "body"], "query": "nosql"}}!
]!
}!
},!
"filter": {!
"range": {"creation_date": {"from": "2013-01-01"}}!
}!
}!
},!
"script": "(_score + 1) * doc[\"rating\"].value"!
}!
},!
"fields": ["title", "rating", "creation_date"],!
"highlight": { !
"fields": { !
"title": {"fragment_size" : 50},!
"body": {"fragment_size" : 50}!
} !
},!
"aggs": {!
"tags": {!
"terms": {"field": "tags"}!
}, !
"frequency": {!
"date_histogram": {"field": "creation_date", "interval": "month"}!
}!
}!
}'!
!
Find questions that!
• Were asked last year!
• Contain “mysql” in title
or body!
• Don't contain “nosql”!
• Have answer that has
“nosql” in title or body!
• Include question rating
into score calculation!
• Highlight matches in
html!
• Aggregate over time
and tags!
• ….