首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >Elasticsearch中不区分大小写的通配符搜索

Elasticsearch中不区分大小写的通配符搜索
EN

Stack Overflow用户
提问于 2018-05-30 18:26:27
回答 1查看 2K关注 0票数 0

我刚刚开始从事elasticsearch的工作。我有一个索引"new_index“,映射如下:

代码语言:javascript
复制
"new_index" : {
    "aliases" : { },
    "mappings" : {
      "current" : {
        "properties" : {
          "did" : {
            "type" : "integer"
          },
          "fil_date" : {
            "type" : "double"
          },
          "file_nr" : {
            "type" : "double"
          },
          "id" : {
            "type" : "integer"
          },
          "mark_text" : {
            "type" : "text"
          },
          "mark_type_id" : {
            "type" : "text"
          },
          "markdescr" : {
            "type" : "text"
          },
          "markdescrtext" : {
            "type" : "text"
          },
          "niceclmain" : {
            "type" : "double"
          },
          "owname" : {
            "type" : "text"
          },
          "statusapplication" : {
            "type" : "text"
          }
        }
      }
    },
    "settings" : {
      "index" : {
        "creation_date" : "1527665866982",
        "number_of_shards" : "5",
        "number_of_replicas" : "1",
        "uuid" : "Py5uWzVTRYqcZuCLcwm-BQ",
        "version" : {
          "created" : "6020499"
        },
        "provided_name" : "new_index"
      }
    }
  }

现在我想搜索字段"mark_text“。我有两种类型的搜索1.如果我搜索"smart",结果应该只包含不区分大小写的单词"smart“。2.它应该像我们使用的LIKE "%smart%“一样搜索,并且不区分大小写。

我已经得到了第二个搜索案例的查询。但是,我想知道是否有任何解决方案可以用于这两种搜索情况。

编辑:我用于搜索案例1的查询是:

代码语言:javascript
复制
GET _search
{
  "query": {
    "bool": {
      "must" : [
        {
          "match": {
            "mark_text": "smart"
          }
        }  
      ]
    }
  }
}

查询搜索案例2:

代码语言:javascript
复制
GET _search
{
  "query": {
    "bool": {
      "must" : [
        {
          "wildcard": {
            "mark_text": "*smart*"
          }
        }  
      ]
    }
  }
}
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-05-31 18:24:13

我创建了一个新索引,并添加了映射和设置,如下所示:

代码语言:javascript
复制
{
  "new_index5" : {
    "aliases" : { },
    "mappings" : {
      "current" : {
        "properties" : {
          "did" : {
            "type" : "integer"
          },
          "fil_date" : {
            "type" : "double"
          },
          "file_nr" : {
            "type" : "double"
          },
          "filing_date" : {
            "type" : "double"
          },
          "id" : {
            "type" : "integer"
          },
          "mark_identification" : {
            "type" : "keyword",
            "normalizer" : "lowercase_normalizer"
          },
          "mark_text" : {
            "type" : "keyword",
            "normalizer" : "lowercase_normalizer"
          },
          "mark_type_id" : {
            "type" : "text"
          },
          "markdescr" : {
            "type" : "text"
          },
          "markdescrtext" : {
            "type" : "text"
          },
          "niceclmain" : {
            "type" : "double"
          },
          "owname" : {
            "type" : "keyword",
            "normalizer" : "lowercase_normalizer"
          },
          "party_name" : {
            "type" : "keyword",
            "normalizer" : "lowercase_normalizer"
          },
          "primary_code" : {
            "type" : "text"
          },
          "registration_date" : {
            "type" : "double"
          },
          "registration_number" : {
            "type" : "double"
          },
          "serial_number" : {
            "type" : "double"
          },
          "status_code" : {
            "type" : "text"
          },
          "statusapplication" : {
            "type" : "text"
          }
        }
      }
    },
    "settings" : {
      "index" : {
        "number_of_shards" : "5",
        "provided_name" : "new_index5",
        "creation_date" : "1527686957833",
        "analysis" : {
          "normalizer" : {
            "lowercase_normalizer" : {
              "filter" : [
                "lowercase"
              ],
              "type" : "custom",
              "char_filter" : [ ]
            }
          }
        },
        "number_of_replicas" : "1",
        "uuid" : "9YdUrs1cSBuqDJmvSPOm6g",
        "version" : {
          "created" : "6020499"
        }
      }
    }
  }
} 

并在我的查询中为第一个搜索案例添加了聚合,如下所示:

代码语言:javascript
复制
GET _search
{
  "query": {
    "bool": {
      "must" : [
        {
          "match": {
              "mark_text": "smart"
          }
        }
      ]
    }
  },
  "aggs": {
    "mark_texts": {
      "terms": {
        "field": "mark_text"
      }
    }
  }
}

它给我的结果包括“聪明”和“聪明”。

对于第二个搜索案例,我使用的是模糊。

我仍然不知道聚合和规格化是如何解决我的问题的。但是,我正在尝试去理解它。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/50602321

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档