【问题标题】:Elasticsearch 6.3.2 - how to search part-words using all fields on this index?Elasticsearch 6.3.2 - 如何使用该索引上的所有字段搜索部分词?
【发布时间】:2018-08-14 11:49:34
【问题描述】:
  1. 您对创建搜索请求有任何想法吗?多重匹配+部分词搜索。

 {
      "shop_index": {
          "settings": {
              "index": {
                  "number_of_shards": "5",
                  "provided_name": "shop_index",
                  "creation_date": "1534235625279",
                  "analysis": {
                      "filter": {
                          "nGram_filter": {
                              "token_chars": [
                                  "letter",
                                  "digit",
                                  "punctuation",
                                  "symbol"
                              ],
                              "min_gram": "2",
                              "type": "nGram",
                              "max_gram": "20"
                          }
                      },
                      "analyzer": {
                          "nGram_analyzer": {
                              "filter": [
                                  "lowercase",
                                  "asciifolding",
                                  "nGram_filter"
                              ],
                              "type": "custom",
                              "tokenizer": "whitespace"
                          },
                          "whitespace_analyzer": {
                              "filter": [
                                  "lowercase",
                                  "asciifolding"
                              ],
                              "type": "custom",
                              "tokenizer": "whitespace"
                          }
                      }
                  },
                  "number_of_replicas": "1",
                  "uuid": "SBB9u344RVGm1QQUo-rVMg",
                  "version": {
                      "created": "6030299"
                  }
              }
          }
      }
    }
  1. 映射

{
      "shop_index": {
          "mappings": {
              "products": {
                  "properties": {
                      "html_keywords": {
                          "type": "text"
                      },
                      "html_title": {
                          "type": "text"
                      },
                      "name": {
                          "type": "text"
                      }
                  }
              }
          }
      }
    }
  1. 我想搜索短语,例如 -> 搜索“HOUSE”
    • 打字 -> “ho” -> 显示“HOUSE”
    • 打字->“侯”->给我看“房子”
    • 打字->“使用”->给我看“房子”
    • 打字 -> “se” -> 显示“HOUSE”

【问题讨论】:

    标签: elasticsearch search search-engine elasticsearch-6


    【解决方案1】:

    您可以使用模糊查询 - https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-fuzzy-query.html 来实现它。还可以考虑将它与 slop (允许的术语相距多远)结合起来,并使用 multi_match 在多个字段中进行搜索。

    示例查询:

    {
        "query":
        {
            "multi_match":
            {
                "fields": ["field1", "field2"],
                "query": "hous",
                "slop": 3,
                "fuzziness": "AUTO"
            }
        }
    }
    

    【讨论】:

    猜你喜欢
    • 2016-05-23
    • 2011-09-21
    • 2016-01-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-04-13
    • 2016-11-26
    • 1970-01-01
    相关资源
    最近更新 更多