【问题标题】:How to make an elasticsearch mapping to find both plural and singular?如何进行弹性搜索映射以查找复数和单数?
【发布时间】:2014-07-14 16:32:36
【问题描述】:

我使用的是弹性搜索 1.2.1 版

该属性的存储值是shoes,该字段的分析器是雪球,尽管如此,当我搜索shoes 时,ES 还是找不到它。当我搜索 shoe 时,它会找到文档...

这是我的查询:

{
  "query": {
    "filtered": {
      "query": {
        "match_all": {}
      },
      "filter": {
        "or": [
          {
            "term": {
              "category": "shoes"
            }
          },
          {
            "term": {
              "sub_category1": "shoes"
            }
          },
          {
            "term": {
              "sub_category2": "shoes"
            }
          },
          {
            "term": {
              "brand": "shoes"
            }
          },
          {
            "term": {
              "shop": "shoes"
            }
          }
        ]
      }
    }
  },
  "aggregations": {
    "category": {
      "terms": {
        "field": "category"
      }
    },
    "sub_category1": {
      "terms": {
        "field": "sub_category1"
      },
      "aggregations": {
        "discount": {
          "avg": {
            "field": "discount_percentage"
          }
        }
      }
    }
  }
}

这是我的映射:

"mappings": {
      "item": {
        "properties": {
          "brand": {
            "type": "string",
            "analyzer": "snowball"
          },
          "category": {
            "type": "string",
            "analyzer": "snowball"
          },
          "color": {
            "type": "string"
          },
          "created_at": {
            "type": "date",
            "format": "dateOptionalTime"
          },
          "discount_percentage": {
            "type": "long"
          },
          "domain_name": {
            "type": "string"
          },
          "id": {
            "type": "long"
          },
          "image": {
            "type": "string"
          },
          "item_name": {
            "type": "string"
          },
          "link": {
            "type": "string"
          },
          "need_indexing": {
            "type": "boolean"
          },
          "price": {
            "type": "string"
          },
          "price_range": {
            "type": "string"
          },
          "product_key": {
            "type": "string"
          },
          "raw_size": {
            "type": "string"
          },
          "regular_price": {
            "type": "string"
          },
          "sale_price": {
            "type": "string"
          },
          "scrape_run": {
            "type": "string"
          },
          "shop": {
            "type": "string",
            "analyzer": "snowball"
          },
          "size": {
            "type": "string"
          },
          "source_url": {
            "type": "string"
          },
          "sub_category1": {
            "type": "string",
            "analyzer": "snowball"
          },
          "sub_category2": {
            "type": "string",
            "analyzer": "snowball"
          },
          "updated_at": {
            "type": "date",
            "format": "dateOptionalTime"
          }
        }
      }
    }
  }

【问题讨论】:

    标签: elasticsearch stemming


    【解决方案1】:

    问题是您正在使用 Snowball 进行索引,它将“鞋子”归结为“鞋子”,但随后运行 match_all 查询并使用术语过滤器查找未分析的术语:

    词条过滤器

    过滤具有包含术语(未分析)的字段的文档。 类似于术语查询,只是它充当过滤器。可以安放 在接受过滤器的查询中

    这就是“鞋”匹配的原因 - 您正在搜索索引中的原始术语。

    一般来说,当您设置复杂的索引和查询时间分析时,您希望使某些内容匹配 - 因此,如果您在输入的过程中进行词干(例如使用 Snowball),您需要确保在搜索时进行词干.

    对于您的情况,我会尝试使用查询过滤器而不是术语过滤器:

    查询过滤器

    包装任何要用作过滤器的查询。可以放在查询中 接受过滤器。

    http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/query-dsl-query-filter.html

    【讨论】:

      猜你喜欢
      • 2014-06-07
      • 2021-10-26
      • 1970-01-01
      • 2017-06-25
      • 2020-07-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多