Last active
May 31, 2018 23:10
-
-
Save ammist/6d0768d972ccb0109d2125780c7da82f to your computer and use it in GitHub Desktop.
ElasticSearch Queries
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.