Elasticsearch 没有 return jsonp

Elasticsearch does not return jsonp

我正在尝试将我的聚合物元素连接到我自己的弹性搜索服务器。 我的第一个问题是,它们在两个不同的端口上,因此由于跨域问题而不得不选择 JSONP。

所以我发现,我只需要添加 http.jsonp.enable:真 在 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。 为什么我的 elasticsearch 服务器格式不正确?

您使用的是 v2.0 之前的版本吗?看起来他们在 2.0 (elastic.co/guide/en/elasticsearch/reference/2.2/…) 中删除了 jsonp。

还有pretty%%callback%%看起来也不对,%%callback%%宏通常需要是name的值(比如onload=%%callback%%)。该元素将 %%callback%% 替换为为您生成的全局函数的名称。