2013-12-07 103 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