2014-09-24 60 views
0

我第一次遇到elasticsearch。 Elasticsearch與SVN一起使用。如何構建匹配查詢以在路徑字符串中進行搜索

我需要找到提交到一個特定的文件夾。例如有兩個分支:

  1. /branches/0.10.2/....
  2. /branches/0.10.2-hotfix/....

這種查詢

{ 
    "query": { 
    "bool": { 
     "should": [ 
     { 
      "indices": { 
      "indices": [ 
       "5439ce1e-e92f-4759-b0c0-3a753b1703b6" 
      ], 
      "query": { 
       "bool": { 
       "must": [ 
        { 
        "range": { 
         "revision": { 
         "from": 413493, 
         "to": 415000 
         } 
        } 
        }, 
        { 
        "span_first": { 
         "match": { 
         "span_term": { 
          "path": "branches" 
         } 
         }, 
         "end": 1 
        } 
        }, 
        {         _ 
        "match": {      | 
         "path": "0.10.2-hotfix" <------| 
        }         | 
        }         _| 
       ] 
       } 
      }, 
      "no_match_query": "none" 
      } 
     } 
     ] 
    } 
    } 
} 

返回我在兩個文件夾中提交。

如何查找提交到0.10.20.10.2-hotfix

回答

0

嘗試使用match_phrase(這對於match一個亞型語法糖):

{ 
    "query":{ 
     "bool":{ 
     "should":[ 
      { 
       "indices":{ 
        "indices":[ 
        "5439ce1e-e92f-4759-b0c0-3a753b1703b6" 
        ], 
        "query":{ 
        "bool":{ 
         "must":[ 
          { 
           "range":{ 
           "revision":{ 
            "from":413493, 
            "to":415000 
           } 
           } 
          }, 
          { 
           "span_first":{ 
           "match":{ 
            "span_term":{ 
             "path":"branches" 
            } 
           }, 
           "end":1 
           } 
          }, 
          { 
           "match_phrase":{ 
           "path":"0.10.2-hotfix" 
           } 
          } 
         ] 
        } 
        }, 
        "no_match_query":"none" 
       } 
      } 
     ] 
     } 
    } 
} 
+0

它適用於* 0.10.2,修補程序*但是* 0.10.2 *返回承諾這兩個文件夾。 – 2014-09-24 07:16:19

+0

我認爲它需要使用斜槓。但{「match_phrase」:「path」:「/ 0.10.2 /」}不會改變任何內容。它仍然向兩個文件夾提交提交。 – 2014-09-24 07:21:26

+0

我認爲這可能需要爲該字段創建一個「未分析」映射。 http://www.elasticsearch.org/guide/en/elasticsearch/guide/current/_finding_exact_values.html – Ashalynd 2014-09-24 07:48:24