Created
December 29, 2019 20:46
-
-
Save abhinavraj23/28ef8e92f85d202f70e702589417a954 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
getPopularSearches = value => { | |
var headers = new Headers(); | |
//This the DSL query for searching according to given value | |
const data = { | |
"query": { | |
"bool": { | |
"must": [ | |
{ | |
"bool": { | |
"must": { | |
"bool": { | |
"should": [ | |
{ | |
"multi_match": { | |
"query": value, | |
"fields": [ | |
"key" | |
], | |
"type": "best_fields", | |
"operator": "or", | |
"fuzziness": 0 | |
} | |
}, | |
{ | |
"multi_match": { | |
"query": value, | |
"fields": [ | |
"key" | |
], | |
"type": "phrase_prefix", | |
"operator": "or" | |
} | |
} | |
], | |
"minimum_should_match": "1" | |
} | |
} | |
} | |
} | |
] | |
} | |
}, | |
"size": 20 | |
} | |
headers.append('Authorization', 'Basic ' + btoa(USERNAME + ':' + PASSWORD)); | |
headers.append('Content-Type', 'application/json'); | |
fetch(ARC_CLUSTER_URL + "/.suggestions/_search", | |
{ | |
method: 'POST', | |
body: JSON.stringify(data), | |
headers: headers | |
}).then(res => res.json()) | |
.then( | |
(result) => { | |
console.log("result", result.hits.hits); | |
var src = result.hits.hits | |
var arr = []; | |
for (var i = 0; i < src.length; i++) { | |
arr.push(src[i]["_source"]["key"]); | |
} | |
//save the popular searches in the state | |
this.setState({ | |
popular_searches: arr | |
}) | |
}, | |
(error) => { | |
console.log("Error is", error); | |
} | |
) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment