Created
September 4, 2011 17:59
-
-
Save phillro/1193227 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> |
better to use Edge NGram Tokenizer
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Why is it my URL getting changed while making an ajax call?
I have specified url as
http://localhost:9200/company/external/_search
but it is making an ajax request tohttp://localhost:3000/<my_current_controller>/<my_current_action>