我有这个查询在'Sense'中使用chrome扩展(基本上只是一个CURL) - 但是,当我通过XHR请求(angular的$ http)运行它时,它返回'ALL'而不是过滤结果,并且没有错误。我已经进行了双重和三重检查,我的查询完全相同。以下查询在Sense中工作,但不能作为具有GET或POST HTTPVerbs的查询字符串
POST product/_search
{
"from": 0,
"query": {
"bool" : {
"should" : {
"function_score": {
"filter": {
"or" : [
{ "wildcard": { "brand.name":"*fapl*" } },
{ "wildcard": { "brand.name":"*women*" } },
{ "wildcard": { "category.name":"*fapl*" } },
{ "wildcard": { "category.name":"*women*" } }
]
},
"boost" : 1,
"functions":[
{
"filter": {
"wildcard": {
"brand.name":"*fapl*"
}
},
"weight":1.2
},
{
"filter": {
"bool":{
"should": [
{
"wildcard": {
"category.name":"*fapl*"
}
},
{
"wildcard": {
"category.name":"*women*"
}
}
]
}
},
"weight":1.1
}
],
"max_boost": 13,
"score_mode": "multiply",
"boost_mode": "multiply",
"min_score" : 0.5
}
}
}
},
"size": 100,
"sort": [ "_score" ]
}
var params = {}, target = "product/_search"
params.size=100
params.from=0
params.query = { /*... that whole query mess here...*/ }
params.sort = [ "_score" ]
$http({
method: "POST",
url: CONSTANTS.ELASTICSEARCH_HTTPS + target,
skipAuthorization: true,
withCredentials: true,
headers: { Authorization: CONSTANTS.ELASTICSEARCH_AUTH },
params: params
})
- 感觉 -
{
"took": 6,
"timed_out": false,
"_shards": {
"total": 1,
"successful": 1,
"failed": 0
},
"hits": {
"total": 111,
"max_score": 1.32,
"hits": [
- XHR2请求 -
{
"took": 2,
"timed_out": false,
"_shards": {
"total": 1,
"successful": 1,
"failed": 0
},
"hits": {
"total": 3547,
"max_score": 1,
"hits": [
- 单个结果的外观 -
{
"_index": "product",
"_type": "staging",
"_id": "208",
"_score": 1.32,
"_source": {
"name": "Smoked Brown 122222",
"images": [{
"width": 1172,
"height": 816,
"imageUrl": "https://www.someurl.com1"
}, {
"width": 1172,
"height": 816,
"imageUrl": "https://cdn.*.*.com"
}, {
"width": 1172,
"height": 816,
"imageUrl": "https://cdn.*.*.com"
}, {
"width": 1172,
"height": 816,
"imageUrl": "https://cdn.*.*.com"
}],
"status": null,
"description": "Some Description here",
"url": null,
"created_at": "2016-03-24T05:05:52.101Z",
"id": 208,
"bId": 7,
"cId": 2,
"band": {
"name": "Some CO",
"displayname": "some hey",
"id": 7
},
"category": {
"name": "Women",
"breadcrumb": "",
"id": 2
},
"tags": []
}
}
答案 0 :(得分:1)
当您使用空体发布到Elasticsearch时,它与获取该端点的方式相同。所以我怀疑这里发生的是实际的查询正文没有被提交。在查看Angular的$http
documentation后,您似乎正在使用params
传递查询正文而不是使用data
,请尝试切换{{ 1}}到params
,看看它是否适合你。