-
-
Save ivanionut/8f4067abe41ae4126d0c to your computer and use it in GitHub Desktop.
Elasticsearch autocomplete example with cross origin resource sharing
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
<html> | |
<head> | |
<link rel="stylesheet" href="/examples/stylesheets/ui-lightness/jquery-ui-1.8.16.custom.css" type="css"> | |
<script type="text/javascript" src="/examples/javascripts/jquery.min.js"></script> | |
<script type="text/javascript" src="/examples/javascripts/jquery.base64.min.js"></script> | |
<script type="text/javascript" src="/examples/javascripts/jquery-ui-1.8.16.custom.min.js"></script> | |
<script type="text/javascript" src="/examples/javascripts/jquery.tmpl.min.js"></script> | |
</head> | |
<body> | |
<script> | |
$(function() { | |
$("#keyword").autocomplete({ | |
source: function(request, response) { | |
var wildcard = { "name": "*" + request.term.toLowerCase() + "*" }; | |
var postData = { | |
"query": { "wildcard": wildcard }, | |
"fields": ["name", "_id"] | |
}; | |
$.ajax({ | |
url: "https://esh01.elasticsearchhq.com:9200/skyfetch2/location/_search", | |
type: "POST", | |
dataType: "JSON", | |
data: JSON.stringify(postData), | |
success: function(data) { | |
response($.map(data.hits.hits, function(item) { | |
return { | |
label: item.fields.name, | |
id: item.fields._id | |
} | |
})); | |
}, | |
}); | |
}, | |
minLength: 2 | |
}) | |
}); | |
</script> | |
<div class="demo"> | |
<h1>Autocomplete using cross origin resource sharing with elasticsearch</h1> | |
<br> | |
<div class="ui-widget"> | |
<label for="keyword">Keyword: </label> | |
<input id="keyword"> | |
</div> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment