【发布时间】:2013-02-09 23:45:57
【问题描述】:
在弹性搜索中,这个过滤器
{
"bool": {
"must": {
"term": {
"article.title": "google"
}
}
}
}
正确返回标题中带有“google”的文章。
然而,
{
"bool": {
"must": {
"term": {
"article.title": "google earth"
}
}
}
}
不返回任何结果,尽管有些文章的标题中包含确切的词“google earth”。我希望它这样做。
完整的查询:
{
"size": 200,
"filter": {
"bool": {
"must": {
"term": {
"article.title": "google maps"
}
}
}
},
{
"range": {
"created_date": {
"from": "2013-01-11T02:14:03.352Z"
}
}
}]
}
}
如您所见,我没有“查询”——只有过滤器、大小和范围。所以我认为 ElasticSearch 正在使用默认分析器...?
我误会了什么?
编辑:对于那些正在寻找解决方案的人,这是我的过滤器:
{
"query": {
"bool": {
"must": {
"must_match": {
"article.title": "google earth"
}
}
}
}
}
节点(1)我们用“query”包装了布尔过滤器,(2)“term”更改为“must_match”,这导致整个短语被匹配(而不是“match”,它将搜索article.title 与谷歌地球上的标准分析器)。
完整的查询如下所示:
{
"size": 200,
"filter": {
"query": {
"bool": {
"must": {
"must_match": {
"article.title": "google earth"
}
}
}
}
}
}
FWIW,我在“过滤器”字段(而不是使用标准查询)中有这个条件的原因是有时我想使用“must_not”而不是“must_not”,有时我还添加其他查询的元素。
【问题讨论】:
-
您的分析器对于 article.title 的外观如何?如果您使用“关键字”以外的任何内容分析该字段,则该字段将被标记为 [google] 和 [earth],这将使其无法匹配。
-
嗯,查询中的文章是否被转移到过滤器?我更新了我的问题以说明我的意思。
标签: elasticsearch