Elasticsearch不返回jsonp

时间:2016-02-05 11:20:41

标签: json ajax elasticsearch polymer jsonp

我试图将我的聚合物元素连接到我自己的elasticsearch-server。 我的第一个问题是,它们位于两个不同的端口上,因此必须选择JSONP,因为跨域问题。

所以我发现,我只需要添加     http.jsonp.enable:true 在elasticsearch.yml。

我只是通过执行" 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>

在Google Chrome浏览器中,我收到了来自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。 为什么我的弹性搜索服务器,而不是格式化?

1 个答案:

答案 0 :(得分:2)

你是否在v2.0之前?看起来他们在2.0(elastic.co/guide/en/elasticsearch/reference/2.2/…)中删除了jsonp。

同样pretty%%callback%%看起来不正确,%%callback%%宏通常需要是名称的值(如onload=%%callback%%)。该元素将%%callback%%替换为为您生成的全局函数的名称。