2015-03-13 104 views
0

我使用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"}}]} 
+1

什麼是你的查詢?即你作爲'$ params'傳遞了什麼? – 2015-03-13 09:59:47

+0

@king_nak我已更新該問題;請立即查詢 – Dau 2015-03-13 10:23:18

回答

1

我找到了解決辦法;下面是正確的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"}}]} 

問題出在匹配查詢階段;我在匹配查詢中追加參數作爲嵌套數組。

現在我已刪除了嵌套的數組,並附加匹配查詢階段,選項順序排列

謝謝你們爲您的聯合調度研究

1

問題可能是你在使用空白過濾器的查詢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