2016-02-05 81 views
1

即時嘗試將我的聚合物元素連接到我自己的elasticsearch服務器。 我的第一個問題是,它們位於兩個不同的端口上,所以必須選擇JSONP才能解決跨域問題。Elasticsearch不會返回jsonp

所以我發現,我只需在elasticsearch.yml中添加 http.jsonp.enable:true 。

我只是通過執行「elasticsearch.bat」來啓動服務器。 我已經索引了數據。

如果我嘗試通過iron-jsonp-library加載API,那麼我總是會收到意外的令牌錯誤。

<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> 

在谷歌瀏覽器,我得到以下結果由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"}}]}} 

由於JSONP的一些互聯網知識,它不是JSONP。 爲什麼我的elasticsearch服務器,格式不正確?

+0

你嘗試過使用'iron-ajax'嗎? – Srik

+2

您是否使用v2.0?看起來他們在2.0中刪除了jsonp(https://www.elastic.co/guide/en/elasticsearch/reference/2.2/breaking_20_setting_changes.html#_jsonp_support)。否則'pretty %% callback %%''看起來不正確,'%% callback %%'參數通常需要一個名字(比如'onload = %% callback %%')。 –

+0

@Srik - 是的,我第一次指向iron-ajax,使用它,但後來我得到了跨域錯誤。所以我需要使用其他的東西。 – Marius

回答

2

您是否使用v2.0?看起來他們在2.0中刪除了jsonp(elastic.co/guide/en/elasticsearch/reference/2.2/…)。

另外pretty%%callback%%看起來不正確,%%callback%%宏通常需要是名稱的值(如onload=%%callback%%)。該元素將替換爲您生成的全局函數的名稱%%callback%%