I have a script written in Vue.js and I am looking to incorporate an Elasticsearch API method.
// ./main.js
var Vue = require('vue');
Vue.use(require('vue-resource'));
import ES from './elasticsearch.js';
new Vue({
el: 'body',
methods: {
search: function() {
// need to implement calling the es.search method here...
}
}
});
Here is the Elasticsearch script for reference:
// ./elasticsearch.js
var es = require('elasticsearch');
var client = new es.Client({
host: 'localhost:9200'
,log: 'trace'
});
client.search({
index: 'my_index',
type: 'my_type',
body: {
fields: {},
query: {
match: {
file_content: 'search_text'
}
}
}
}).then(function (resp) {
var hits = resp.hits.hits;
}, function (err) {
console.trace(err.message);
});
My goal is to call the client.search method within the search method in main.js and send the search text to my server. How can this be achieved? Is there a way to access and use the elasticsearch object within a vuejs method?
Any suggestions or guidance would be greatly appreciated!