Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Elasticsearch autocomplete example with cross origin resource sharing
<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>
$(function() {
source: function(request, response) {
var wildcard = { "name": "*" + request.term.toLowerCase() + "*" };
var postData = {
"query": { "wildcard": wildcard },
"fields": ["name", "_id"]
url: "",
type: "POST",
dataType: "JSON",
data: JSON.stringify(postData),
success: function(data) {
response($.map(data.hits.hits, function(item) {
return {
id: item.fields._id
minLength: 2
<div class="demo">
<h1>Autocomplete using cross origin resource sharing with elasticsearch</h1>
<div class="ui-widget">
<label for="keyword">Keyword: </label>
<input id="keyword">
Copy link

cassianotartari commented Jun 3, 2013

Sorry, I'm starting with Elastica and I couldn't get it working in my code, I've made some research about it without success. Can you explain what are the parameters? I my configuration I just know how to make a search like this: http://localhost:9200/my_index/my_type/_search?q=[search_string] . What it the wildcard, name, fields,.... ? Thank you!

Copy link

sriharshakappala commented Apr 2, 2015

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 to http://localhost:3000/<my_current_controller>/<my_current_action>

Copy link

kamalbctg commented Dec 31, 2015

better to use Edge NGram Tokenizer

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment