Skip to content

Instantly share code, notes, and snippets.

@ammist
Last active May 31, 2018 23:10
Show Gist options
  • Save ammist/6d0768d972ccb0109d2125780c7da82f to your computer and use it in GitHub Desktop.
Save ammist/6d0768d972ccb0109d2125780c7da82f to your computer and use it in GitHub Desktop.
ElasticSearch Queries
GET _search
{
"size":24,
"from":0,
"query" : {
"function_score" : {
"query":{
"multi_match":{
"query":"bagel",
"fields":["post_title^3","post_excerpt^2","post_content","post_author.display_name","terms.category.name", "terms.resource-category.name","terms.post_tag.name"],
"type":"cross_fields",
"operator":"or"}
},
"functions": [
{"filter": {
"range" : { "post_date.date": { "gte" : "now-1y", "lte" : "now" } }} ,
"weight": 5
},
{"filter": {
"range" : { "post_date.date": { "gte" : "now-4y", "lt" : "now-1y" } }} ,
"weight": 2
}
],
"boost_mode": "multiply"
}
},
"_source": ["post_id", "post_title", "post_author.display_name", "post_date.date"]
}
@ammist
Copy link
Author

ammist commented May 31, 2018

This query retrieves all posts with the text "bagel", and prioritizes results from the last year higher than older content. Uses ElasticSearch with a WordPress document repository.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment