2

i want to search on the 'Index' and 'Type' that is input from the user through a html form. I'm new to both angular and Elasticsearch.

i tried using this code and binding the variables through ng-model

ExampleApp.controller('MatchController', function ($scope, client, esFactory) {
    function click($scope){
        $scope.index = '';
        $scope.type = '';
        $scope.key = '';

client.search({
index:  $scope.index ,
type: $scope.type ,
size: 50,
body: {
"query":
    {
        "match": {

            name:  $scope.key
        }   
    },
}

html code...

<input type="text" ng-model="index" id="index" /> <br><br>
<input type="text" ng-model="type" id="type" /><br><br>
<input type="text" ng-model="key" id="key" /><br><br>
<input type="button" value="search" onclick="click()">

Is it possible to do this??? if so how??

many thanks.

1 Answer 1

1

You need to create a service to connect and query elasticsearch using your functions.

https://www.sitepoint.com/building-recipe-search-site-angular-elasticsearch/

The above link shows you how to create and run queries via elasticsearch and AngularJS. The service that I mentioned is written in the last block of code. I suggest you read the whole article though to give you a better understanding.

You're mostly on the right track except your whole client.search part needs to go into a service which you call, otherwise whenever the controller is called that will be called too which you don't want happening.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.