【问题标题】:Elastic search - text search not working弹性搜索 - 文本搜索不起作用
【发布时间】:2016-10-31 15:46:53
【问题描述】:

我需要为多个字段搜索带有特殊字符的文本内容。 例如:name_text 包含-“你好,你好吗?”

如果我搜索“how”、“are”这个词,我得到了结果,但如果是“thow”,我没有得到结果。

用于搜索

{"simple_query_string": {
                        "query":  "thow",
                        "flags" : "OR|AND|PREFIX",
                       "analyzer": "snowball",
                        "fields": [ "name_text", "address_text" ]
                        }

我用过 nGram,这是我的代码

  "settings":{ "index": {
  "analysis": {
            "analyzer": {
                "autocomplete_term": {
                    "tokenizer": "autocomplete_edge",
                    "filter": [
                        "lowercase"
                    ]
                },

                "autocomplete_search": {
                    "tokenizer": "keyword",
                    "filter": [
                        "lowercase"
                    ]
                }
            },
            "tokenizer": {
                "autocomplete_edge": {
                    "type": "nGram",
                    "min_gram": 1,
                    "max_gram": 100
                }
            }
        }
}

和映射

"name_text": {
    "type": "string",
    "analyzer": "autocomplete_term"
    "search_analyzer": "autocomplete_search"
},
"address_text": {
    "type": "string",
     "analyzer": "autocomplete_term"
    "search_analyzer": "autocomplete_search"
}

我的代码有什么问题吗?请帮帮我

【问题讨论】:

    标签: php elasticsearch


    【解决方案1】:

    你需要模糊搜索才能匹配:

    "simple_query_string": {
      "query": "thow~1",
      "flags": "OR|AND|PREFIX|FUZZY",
      "analyzer": "snowball",
      "fields": [
        "name_text",
        "address_text"
      ]
    }
    

    【讨论】:

    • 嗨.. 它在 aws 弹性搜索中不起作用。当我们给任何特殊字符“#”、“@”等返回零结果时
    • 请发布另一个问题。对于最初的问题,已经提供了答案。处理特殊字符是另一回事。问候。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-10-26
    • 1970-01-01
    相关资源
    最近更新 更多