我正在尝试将聚合物元素连接到我自己的elasticsearch-server。
我的第一个问题是,它们位于两个不同的端口上,因此由于跨域问题,它不得不选择JSONP。
所以我发现,我只需要添加
http.jsonp.enable:true
在elasticsearch.yml中。
我只是通过执行“elasticsearch.bat”来启动服务器。
我已经索引了数据。
如果我尝试通过iron-jsonp-library加载API,那么我总是会遇到意外的 token 错误。
<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服务器不正确格式化?
最佳答案
您是否在v2.0之前?看起来他们在2.0(elastic.co/guide/en/elasticsearch/reference/2.2/…)中删除了jsonp。
另外pretty%%callback%%
看起来也不正确,%%callback%%
宏通常需要是name的值(例如onload=%%callback%%
)。元素将%%callback%%
替换为为您生成的全局函数的名称。
关于json - Elasticsearch不返回jsonp,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35222869/