JavaScript - Cannot index new data (on client side)


(Susan Liu) #1

I have a #elastic-submit on a search submit button - every time someone clicks it, I want to grab their IP address and index the new data into my existing index called "html5-es-search." It took me a long time to figure out how to attain the IP address, but now that I'm able to - it seems that the elastic client only has a valid function for close(). There is no create() or index(). Can someone please help me? What am I doing wrong?

    $("#elastic-submit").click(function (e) {
        $.getJSON("https://api.ipify.org?format=jsonp&callback=?",
            function(json)
            {
                var searchField = document.getElementById("elastic");

                if (searchField != null)
                {
                    ConnectToES();

                    var input = $(searchField).val();
                    var target = _"html5-es-search";
                    var result = client.index({
                        "index": target,
                        "body": {
                            "ip_address": json.id,
                            "input": input
                        }
                    }, function (error, resp) {
                        console.log(resp);
                    });
                }
            }
        );
    });


(system) #2

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.