在elasticsearch中使用php curl搜索
问题描述:
我使用elasticsearch创建了应用程序,除了使用php curl进行搜索外,一切都运行完好;所述误差低于在elasticsearch中使用php curl搜索
[match] query parsed in simplified form, with direct field name, but included more options than just the field name, possibly use its 'options' form, with 'query' element?]
但相同的查询在命令行运行完美。
当我做了一些更改,我发现这是由curl POST发生的。
我使用下面的代码来运行PHP的卷曲,并试图GET方法太
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_TIMEOUT, 200);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, strtoupper($method));
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($params));
$response = curl_exec($ch);
curl_close ($ch);
和查询
{"query":{"filtered":{"query":{"bool":{"should":[{"bool":{"should":[{"match_phrase":{"name":"india"}}],"boost":16}},{"bool":{"should":[{"match_phrase":{"description":"india"}}],"boost":8}},{"bool":{"should":[{"match":{"name":{"query":"india","analyzer":"standard"}}},{"match":{"description":{"query":"india","analyzer":"standard"}}}],"boost":4}},{"match":{"name.ngram":[{"query":"india","analyzer":"standard"}]}},{"match":{"description":[{"query":"india","analyzer":"standard"}]}},{"match":{"name.ngram":[{"query":"india","analyzer":"standard","fuzziness":"auto"}]}},{"match":{"description":[{"query":"india","analyzer":"standard","fuzziness":"auto"}]}}],"boost":2}},"filter":{"and":[{"terms":{"type":["book"]}},{"range":{"price":{"from":"1","to":"100"}}}]}}},"from":0,"size":20,"filter":{"and":[]},"sort":[{"popularity":{"order":"desc","missing":"_last"}}]}
答
我找到了解决办法;下面是正确的json
{"query":{"filtered":{"query":{"bool":{"should":[{"bool":{"should":[{"match_phrase":{"name":"india"}}],"boost":16}},{"bool":{"should":[{"match_phrase":{"description":"india"}}],"boost":8}},{"bool":{"should":[{"match":{"name":{"query":"india","analyzer":"standard"}}},{"match":{"description":{"query":"india","analyzer":"standard"}}}],"boost":4}},{"match":{"name.ngram":{"query":"india","analyzer":"standard"}}},{"match":{"description":{"query":"india","analyzer":"standard"}}},{"match":{"name.ngram":{"query":"india","analyzer":"standard","fuzziness":"auto"}}},{"match":{"description":{"query":"india","analyzer":"standard","fuzziness":"auto"}}}],"boost":2}},"filter":[]}},"from":0,"size":20,"sort":[{"popularity":{"order":"desc","missing":"_last"}}]}
问题出在匹配查询阶段;我在匹配查询中追加参数作为嵌套数组。
现在我已删除了嵌套的数组,并附加匹配查询阶段,选项顺序排列
谢谢你们为您的联合调度研究
答
问题可能是你在使用空白过滤器的查询dsl。
"filter": {
"and":[]
}
尝试不使用空白过滤器。此外,*过滤器在Elasticsearch 1.0 +版本中重新命名。
更新查询DSL:
{
"query": {
"filtered": {
"query": {
"bool": {
"should": [
{
"bool": {
"should": [
{
"match_phrase": {
"name": "india"
}
}
],
"boost": 16
}
},
{
"bool": {
"should": [
{
"match_phrase": {
"description": "india"
}
}
],
"boost": 8
}
},
{
"bool": {
"should": [
{
"match": {
"name": {
"query": "india",
"analyzer": "standard"
}
}
},
{
"match": {
"description": {
"query": "india",
"analyzer": "standard"
}
}
}
],
"boost": 4
}
},
{
"match": {
"name.ngram": [
{
"query": "india",
"analyzer": "standard"
}
]
}
},
{
"match": {
"description": [
{
"query": "india",
"analyzer": "standard"
}
]
}
},
{
"match": {
"name.ngram": [
{
"query": "india",
"analyzer": "standard",
"fuzziness": "auto"
}
]
}
},
{
"match": {
"description": [
{
"query": "india",
"analyzer": "standard",
"fuzziness": "auto"
}
]
}
}
],
"boost": 2
}
},
"filter": {
"and": [
{
"terms": {
"type": [
"book"
]
}
},
{
"range": {
"price": {
"from": "1",
"to": "100"
}
}
}
]
}
}
},
"from": 0,
"size": 20,
"sort": [
{
"popularity": {
"order": "desc",
"missing": "_last"
}
}
]
}
+0
我已经更新了您提供的查询,并且也给出了相同的错误 – Dau 2015-03-13 10:46:03
什么是你的查询?即你作为'$ params'传递了什么? – 2015-03-13 09:59:47
@king_nak我已更新该问题;请立即查询 – Dau 2015-03-13 10:23:18