我有一个包含field
有价值视频的索引1.flv
.如果我执行以下查询:
"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" } } ] } }
小智.. 6
你所看到的是标准标记器(默认/标准分析器的一部分)的结果,它标记了句点字符(.
)等.请参阅此剧本,了解如何分析它的快速示例.
有很多方法可以通过Elasticsearch实现您想要的功能,例如更新映射并将video
字段的分析器更改为例如keyword
上面提到的分析器,可能使用多字段类型,配置字段映射index: not_analyzed
等,但是简单对您来说可能运行良好的解决方案是确保AND
正在使用运算符.
默认情况下,查询字符串查询使用OR
运算符:
default_operator
:如果未指定显式运算符,则使用默认运算符.例如,使用OR的默认运算符,匈牙利的查询资本将转换为OR匈牙利的资本OR,并且使用AND的默认运算符,相同的查询将转换为AND匈牙利的资本AND.默认值为OR.
因此,要么与运算符明确,要么将其设置为默认值.此剧还显示了这些技术的实际应用(右下方窗格中的搜索#1和搜索#2 - 选项卡).