Search code examples
jsonajaxelasticsearchpolymerjsonp

Elasticsearch does not return jsonp


im trying to connect my polymer element to my own elasticsearch-server. My first problem was, that they are on two different ports, so it had to choose JSONP because of Cross-Domain problems.

So I found out, that I just have to add http.jsonp.enable: true in the elasticsearch.yml.

Im starting the server simply by executing the "elasticsearch.bat". I've indexed data.

If I try to load the API via iron-jsonp-library, im always getting an unexpected token error.

<iron-jsonp-library id="libraryLoader"
      library-url="http://127.0.0.1:9200/data/_search?pretty%%callback%%"
      notify-event="api-load"
      callbackName="jsonpCallback">
    </iron-jsonp-library>

In Google Chrome, I'm getting following result from elasticsearch

{"took":2,"timed_out":false,"_shards":{"total":5,"successful":5,"failed":0},"hits":{"total":5,"max_score":1.0,"hits":[{"_index":"data","_type":"data","_id":"5","_score":1.0,"_source":{"id":5,"name":"Meyr","manufacturer":"Meyr","weight":1.0,"price":1.0000,"popularity":1,"instock":true,"includes":"Meyr"}},{"_index":"data","_type":"data","_id":"2","_score":1.0,"_source":{"id":2,"name":"Meier","manufacturer":"Meier","weight":1.0,"price":1.0000,"popularity":1,"instock":true,"includes":"Meier"}},{"_index":"data","_type":"data","_id":"4","_score":1.0,"_source":{"id":4,"name":"Mair","manufacturer":"Mair","weight":1.0,"price":1.0000,"popularity":1,"instock":true,"includes":"Mair"}},{"_index":"data","_type":"data","_id":"1","_score":1.0,"_source":{"id":1,"name":"Maier","manufacturer":"Maier","weight":1.0,"price":1.0000,"popularity":1,"instock":true,"includes":"Maier"}},{"_index":"data","_type":"data","_id":"3","_score":1.0,"_source":{"id":3,"name":"Mayr","manufacturer":"Mayr","weight":1.0,"price":1.0000,"popularity":1,"instock":true,"includes":"Mayr"}}]}}

Due to some internet knowledge of JSONP, its not jsonp. Why is my elasticsearch server, not formatting right?


Solution

  • Are you prior to v2.0? Looks like they removed jsonp in 2.0 (elastic.co/guide/en/elasticsearch/reference/2.2/…).

    Alsopretty%%callback%% doesn't look right, the %%callback%% macro usually needs to be the value of name (like onload=%%callback%%). The element replaces %%callback%% with the name of a global function that is generated for you.