2013-12-07 161 views
5

我有一個包含field視頻的值爲1.flv的索引。如果我執行以下查詢:Elasticsearch query_string完全匹配

"query": { 
    "query_string": { 
     "query": "2.flv" 
    } 
} 

查詢仍然返回1.flv的所有記錄。

任何人都可以指出我正確的解決方案嗎?

下面是1.flv樣品返回的數據(如你所看到的,不存在任何2.flv!)

"hits" : { 
    "total" : 8, 
    "max_score" : 0.625, 
    "hits" : [ { 
     "_index" : "videos", 
     "_type" : "comment", 
     "_id" : "_meta", 
     "_score" : 0.625, 
     "fields" : { 
     "video" : "1.flv", 
     "body" : "Really?" 
     } 
    }, { 
     "_index" : "videos", 
     "_type" : "comment", 
     "_id" : "0fYsYOTHT7O-7P6CVi7l3w", 
     "_score" : 0.625, 
     "fields" : { 
     "video" : "1.flv", 
     "body" : "fadsfasfas" 
     } 
    }, { 
     "_index" : "videos", 
     "_type" : "comment", 
     "_id" : "O9VjgFdmQra6hYxwMdGuTg", 
     "_score" : 0.48553526, 
     "fields" : { 
     "video" : "1.flv", 
     "body" : "Search is hard. Search should be easy." 
     } 
    }, { 
     "_index" : "videos", 
     "_type" : "comment", 
     "_id" : "A6k3FEKKSzKTSAVIT-4EbA", 
     "_score" : 0.48553526, 
     "fields" : { 
     "video" : "1.flv", 
     "body" : "Really?" 
     } 
    }, { 
     "_index" : "videos", 
     "_type" : "comment", 
     "_id" : "eFnnM4PrTSyW6wfxHWdE8A", 
     "_score" : 0.48553526, 
     "fields" : { 
     "video" : "1.flv", 
     "body" : "Hello!" 
     } 
    }, { 
     "_index" : "videos", 
     "_type" : "comment", 
     "_id" : "ZogAiyanQy6ddXA3o7tivg", 
     "_score" : 0.48553526, 
     "fields" : { 
     "video" : "1.flv", 
     "body" : "dcxvxc" 
     } 
    }, { 
     "_index" : "videos", 
     "_type" : "comment", 
     "_id" : "O0HcT7aGTrqKQxF25KsOwQ", 
     "_score" : 0.37158427, 
     "fields" : { 
     "video" : "1.flv", 
     "body" : "Hello!" 
     } 
    }, { 
     "_index" : "videos", 
     "_type" : "comment", 
     "_id" : "l2d53OFITb-etooWEAI0_w", 
     "_score" : 0.37158427, 
     "fields" : { 
     "video" : "1.flv", 
     "body" : "dasdas" 
     } 
    } ] 
    } 
} 
+0

你可以發佈你的映射和預期的結果嗎? – moliware

+0

還有分析儀設置? – shyos

+0

@shyos我不知道我怎麼能得到它。我需要1.flv精確匹配1.flv和2.flv精確匹配只有2.flv(不是1.flv) – user2786037

回答

6

你看到的是標準分詞的結果(默認的一部分/標準分析儀),除了別的以外,它還標記週期字符(.)。有關如何分析它的快速示例,請參見this play

有許多方法來完成你想要Elasticsearch什麼,比如更新映射和更改分析儀的video領域例如以上提到的,可能使用多字段類型,配置字段映射爲keyword分析儀index: not_analyzed等等,但是一個簡單的解決方案可能適用於你,就是確保使用AND運營商。

默認情況下,query string query使用OR操作:

default_operator:如果沒有指定明確的操作員使用的默認操作。例如,對於OR的默認運算符,匈牙利的查詢資本被翻譯爲OR匈牙利的資本OR,並且與AND的默認運算符相同的查詢被翻譯成AND和匈牙利的大寫AND。默認值是OR。

因此,無論是明確的運營商或將其設置爲默認值。 This play也顯示了這兩種技術(搜索#1和搜索#2選項卡在右下方窗格中)。

+0

對於默認的運算符,我忽略了一些... – Dror