【问题标题】:Search any part of word in any column在任何列中搜索单词的任何部分
【发布时间】:2017-01-09 02:17:15
【问题描述】:

我正在尝试搜索全名、电子邮件或电话

例如

如果我开始输入“+16”,它应该显示所有电话号码开头或包含“+16”的用户。全名和邮箱也一样

我的 ES 配置是:

{
   "users" : {
      "mappings" : {
         "user" : {
            "properties" : {
               "full_name" : {
                  "analyzer" : "trigrams",
                  "include_in_all" : true,
                  "type" : "string"
               },
               "phone" : {
                  "type" : "string",
                  "analyzer" : "trigrams",
                  "include_in_all" : true
               },
               "email" : {
                  "analyzer" : "trigrams",
                  "include_in_all" : true,
                  "type" : "string"
               }
            },
            "dynamic" : "false"
         }
      },
      "settings" : {
         "index" : {
            "creation_date" : "1472720529392",
            "number_of_shards" : "5",
            "version" : {
               "created" : "2030599"
            },
            "uuid" : "p9nOhiJ3TLafe6WzwXC5Tg",
            "analysis" : {
               "analyzer" : {
                  "trigrams" : {
                     "filter" : [
                        "lowercase"
                     ],
                     "type" : "custom",
                     "tokenizer" : "my_ngram_tokenizer"
                  }
               },
               "tokenizer" : {
                  "my_ngram_tokenizer" : {
                     "type" : "nGram",
                     "max_gram" : "12",
                     "min_gram" : "2"
                  }
               }
            },
            "number_of_replicas" : "1"
         }
      },
      "aliases" : {},
      "warmers" : {}
   }
}

按姓名的一部分搜索姓名“罗伯特”

curl -XGET 'localhost:9200/users/_search?pretty' -d' { “询问”: { “匹配”: { “_all”:“抢劫” } } }'

没有给出预期的结果,只使用全名。

【问题讨论】:

标签: ruby-on-rails-4 elasticsearch


【解决方案1】:

由于您的分析器设置在full_namephoneemail 字段上,因此您不应使用_all 字段,而是在multi_match 查询中枚举这些字段,如下所示:

curl -XGET 'localhost:9200/users/_search?pretty' -d'{
  "query": {
    "multi_match": {
      "query": "this is a test",
      "fields": [
        "full_name",
        "phone",
        "email"
      ]
    }
  }
}'

【讨论】:

  • 谢谢,效果更好。但仍然无法为手机获得正确的结果。如果我输入 54322543 w/o +167 它根本不搜索
  • 但我提供了我所拥有的一切
猜你喜欢
  • 1970-01-01
  • 2014-05-03
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-06-23
  • 1970-01-01
  • 1970-01-01
  • 2020-01-16
相关资源
最近更新 更多