【发布时间】:2017-10-15 20:03:24
【问题描述】:
当查询有过滤器时,我想使用 Ajax 从 elasticsearch 检索数据。 我正在使用 GET。
我的代码如下:
<script src="http://code.jquery.com/jquery-latest.min.js" type="text/javascript"></script>
<script>
$(document).ready(function(){
$.ajax({
type: 'GET',
url : 'HOST/tomo2o/shop/_search',
crossDomain: true,
data: JSON.stringify({"query":{"match":{"catlev1":"Motors"}}}),
contentType:'application/json; charset=utf-8',
dataType: 'json',
success: function(data) {
console.log(data);
},
error: function(e) {
console.log(e);
}
});
});
</script>
我做了人们建议做的三件事:
- 字符串化 json 过滤器
- 设置数据类型为json
- 设置内容类型为application/json
但我仍然收到以下错误:
GET HOST/tomo2o/shop/_search?{%22query%22:{%22match%22:{%22catlev1%22:%22Motors%22}}} 400 (Bad Request)
【问题讨论】:
标签: json ajax elasticsearch get bad-request