Skip to content

Instantly share code, notes, and snippets.

@victortsaitw12
Last active August 11, 2018 11:42
Show Gist options
  • Select an option

  • Save victortsaitw12/89b2e327a4ed5d47bd0eeb45f367685b to your computer and use it in GitHub Desktop.

Select an option

Save victortsaitw12/89b2e327a4ed5d47bd0eeb45f367685b to your computer and use it in GitHub Desktop.
function ElkfetchData(elasticsearch, coin_type) {
let query_body = {
"query": {
"function_score": {
"query": {
"multi_match": {
"query": coin_type,
"operator": "and",
"fields": ["title", "content"]
}
},
"functions":[
{
"gauss": {
"time": {
"origin": "now",
"scale": "6h",
"offset": "6h",
"decay": 0.5
}
},
"weight": 10
}
]
}
}
};
return Promise.resolve().then(() => {
return elasticsearch.search({
index: 'article',
type: 'article',
body: query_body
});
}).then(function (resp) {
console.log(resp);
var hits = resp.hits.hits;
return hits;
}).catch(err => {
console.log(err.stack);
return [];
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment