【问题标题】:ElasticSearch filtered query and filter termElasticSearch 过滤查询和过滤词
【发布时间】:2015-12-22 17:56:30
【问题描述】:

我正在尝试在 filtered 查询上使用 filter,这就是我正在尝试使用 Sense:

GET myindex/catalog/_search
{
    "query": {
        "filtered": {
            "query": {
                "query_string": {
                  "analyze_wildcard": true,
                    "query": "test",
                    "fields": ["title^3.5", "contributions.authors.name^5", "publisher^2", "formats.productCode^0.5", "description^0.1"],
                    "use_dis_max": true
                }
            },
            "filter": {
                "term": {
                    "sku": "test-687"
                }
            }
        }
    }
}

此查询没有任何命中,但如果我删除 filter 属性,我会得到带有 sku = test-687 的项目。

我不明白为什么带有 filter 的查询没有给我相同的结果。

映射:

{
  "myindex": {
    "mappings": {
      "catalog": {
        "properties": {
          "sku": {
            "type": "string"
          },
          "title": {
            "type": "string"
          },
          "updated_at": {
            "type": "date",
            "format": "strict_date_optional_time||epoch_millis"
          }
        }
      }
    }
  }
}

【问题讨论】:

  • 字段sku 是精确的test-687
  • 术语是小写/大写敏感。您对“sku”字段的映射是什么?
  • 我告诉过你,这正是test-687,不可能是大小写问题。
  • 你使用了什么映射?例如,在我的弹性索引中,我有一个以大写显示的字段,但在映射中它是小写的,我需要使用 term 搜索小写的值
  • 字段名正好是sku:"sku": {"type": "string"}

标签: elasticsearch filter


【解决方案1】:

完整的查询是:

GET myindex/catalog/_search {
  "query": {
    "filtered": {
      "query": {
        "query_string": {
          "analyze_wildcard": true,
            "query": "test",
              "fields": ["title^3.5", "contributions.authors.name^5", "publisher^2", "formats.productCode^0.5", "description^0.1"],
                "use_dis_max": true
        }
      },
        "filter": {
          "bool": {
            "must": {
              "query": {
                "match": {
                  "sku": "test-687"
                }
              }
            }
          }
        }
    }
  }
}

使用默认映射,“使用标准分析器”:

使用带有标准标记过滤器、小写标记过滤器和停止标记过滤器的标准标记器构建标准类型的分析器。

(更多详情her

术语区分大小写,不匹配

【讨论】:

    猜你喜欢
    • 2015-09-08
    • 1970-01-01
    • 1970-01-01
    • 2020-08-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多