首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >基于电话号码的Elasticsearch搜索

基于电话号码的Elasticsearch搜索
EN

Stack Overflow用户
提问于 2016-02-16 11:02:35
回答 1查看 1.4K关注 0票数 1

我有我想要索引的postgres数组列,然后在搜索中使用它。下面是示例,

电话= "+175 (2) 123-25-32","123456789",“+12111-111-11”

我已经使用analyze api分析了标记,elasticsearch将该字段标记为多个字段,如下所示

代码语言:javascript
复制
curl -XGET 'localhost:9200/_analyze' -d '
{
  "analyzer" : "standard",
  "text" : [ "+175 (2) 123-25-32", "123456789", "+12 111-111-11" ]
}'


{
  "tokens": [
    {
      "token": "analyzer",
      "start_offset": 6,
      "end_offset": 14,
      "type": "<ALPHANUM>",
      "position": 1
    },
    {
      "token": "standard",
      "start_offset": 19,
      "end_offset": 27,
      "type": "<ALPHANUM>",
      "position": 2
    },
    {
      "token": "text",
      "start_offset": 33,
      "end_offset": 37,
      "type": "<ALPHANUM>",
      "position": 3
    },
    {
      "token": "175",
      "start_offset": 45,
      "end_offset": 48,
      "type": "<NUM>",
      "position": 4
    },
    {
      "token": "2",
      "start_offset": 50,
      "end_offset": 51,
      "type": "<NUM>",
      "position": 5
    },
    {
      "token": "123",
      "start_offset": 53,
      "end_offset": 56,
      "type": "<NUM>",
      "position": 6
    },
    {
      "token": "25",
      "start_offset": 57,
      "end_offset": 59,
      "type": "<NUM>",
      "position": 7
    },
    {
      "token": "32",
      "start_offset": 60,
      "end_offset": 62,
      "type": "<NUM>",
      "position": 8
    },
    {
      "token": "123456789",
      "start_offset": 66,
      "end_offset": 75,
      "type": "<NUM>",
      "position": 9
    },
    {
      "token": "12",
      "start_offset": 80,
      "end_offset": 82,
      "type": "<NUM>",
      "position": 10
    },
    {
      "token": "111",
      "start_offset": 83,
      "end_offset": 86,
      "type": "<NUM>",
      "position": 11
    },
    {
      "token": "111",
      "start_offset": 87,
      "end_offset": 90,
      "type": "<NUM>",
      "position": 12
    },
    {
      "token": "11",
      "start_offset": 91,
      "end_offset": 93,
      "type": "<NUM>",
      "position": 13
    }
  ]
}

我希望elasticsearch要么不做标记化,要么存储没有特殊字符的数字,例如"+175 (2) 123-25-32“转换为"+17521232532”,或者简单地对数字进行索引,以便在搜索结果中可用。

我的映射如下:

代码语言:javascript
复制
{ :id => { :type => "string"}, :secondary_phones => { :type => "string" } }

下面是我尝试执行查询的方法

代码语言:javascript
复制
      settings = {
        query: {
          filtered: {
            filter: {
              bool: {
                should: [
                  { terms: { phones: [ "+175 (2) 123-25-32", "123456789", "+12 111-111-11" ] } },
                ]
              }
            }
          }
        },
        size: 100,
      }

附注:我也尝试过删除特殊字符,但没有成功。

我相信这是可以实现的,我错过了一些东西。请给我一些建议。

谢谢。

EN

回答 1

Stack Overflow用户

发布于 2016-02-16 11:14:05

如果只想对数据执行精确匹配,就像在terms查询示例中一样,最好的方法是将映射中的index映射参数设置为not_analyzed。看一看documentation here

这将完全禁用对值的分析(或标记化),并将字段内容(数组中的每一项)视为单个标记/关键字。

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

https://stackoverflow.com/questions/35422907

复制
相关文章

相似问题

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