无法在elasticsearch中模糊搜索

时间:2018-08-27 08:23:36

标签: elasticsearch fuzzy-search

我想通过Elasticsearch自动完成服务。我需要“是不是真的”的Google风格。我做了很多研究。我被发现模糊搜索。当我输入“ Alman”时,我只想要Almanya。但是我也收到了乌曼。我怎么只能得到“ almanya”?

    {
        "highlight": {"fields": [{"CountryName": {"type": "plain"}}]},
        "query": {
            "bool": {
                "should": [
                    {
                        "match": {
                            "CountryName": {
                                "boost": 1,
                                "fuzziness": 5,
                                "query": "Alman"
                            }
                        }
                    },
                    {
                        "match": {
                            "CountryNameTurkish": {
                                "boost": 1,
                                "fuzziness": 5,
                                "query": "Alman"
                            }
                        }
                    }
                ]
            }
        }
    }

响应

    {
        "hits": {
            "total": 2,
            "max_score": 1.9666269,
            "hits": [
                {
                    "_index": "country_codes_v1",
                    "_type": "kafka_connect",
                    "_id": "OM",
                    "_score": 1.9666269,
                    "_source": {
                        "CountryCode": "OM",
                        "CountryName": "Oman",
                        "Continent": "Middle East",
                        "CapitalCityCode": "MCT",
                        "Duplicate": 0,
                        "CountrySlug": "om-oman",
                        "CountryNameTurkish": "Umman"
                    }
                },
                {
                    "_index": "country_codes_v1",
                    "_type": "kafka_connect",
                    "_id": "DE",
                    "_score": 1.6418773,
                    "_source": {
                        "CountryCode": "DE",
                        "CountryName": "Germany",
                        "Continent": "Europe",
                        "CapitalCityCode": "BER",
                        "Duplicate": 0,
                        "CountrySlug": "de-germany",
                        "CountryNameTurkish": "Almanya"
                    }
                }
            ]
        }
    }

编辑:我的索引在这里。抱歉,我最初忘了这个。

    {
      "country_codes_v1" : {
        "aliases" : { },
        "mappings" : {
          "kafka_connect" : {
            "_meta" : {
              "model" : "EnuygunCom\\LocationBundle\\Entity\\CountryCodes"
            },
            "dynamic_date_formats" : [ ],
            "properties" : {
              "CapitalCityCode" : {
                "type" : "text"
              },
              "Continent" : {
                "type" : "text"
              },
              "CountryCode" : {
                "type" : "text",
                "analyzer" : "autocomplete"
              },
              "CountryName" : {
                "type" : "text",
                "analyzer" : "autocomplete"
              },
              "CountryNameTurkish" : {
                "type" : "text"
              },
              "CountrySlug" : {
                "type" : "text"
              },
              "Duplicate" : {
                "type" : "text"
              }
            }
          }
        },
        "settings" : {
          "index" : {
            "number_of_shards" : "5",
            "provided_name" : "country_codes_v1",
            "creation_date" : "1535360528153",
            "analysis" : {
              "filter" : {
                "autocomplete_filter" : {
                  "type" : "edge_ngram",
                  "min_gram" : "3",
                  "max_gram" : "5"
                }
              },
              "analyzer" : {
                "autocomplete" : {
                  "filter" : [
                    "autocomplete_filter",
                    "lowercase",
                    "uppercase"
                  ],
                  "type" : "custom",
                  "tokenizer" : "standard"
                }
              }
            },
            "number_of_replicas" : "1",
            "uuid" : "9Z6MQpvoThSkI6y5zedWjg",
            "version" : {
              "created" : "5060599"
            }
          }
        }
      }
    }

0 个答案:

没有答案