【问题标题】:Tokenize string based on delimiter in Elastic search在弹性搜索中基于分隔符标记字符串
【发布时间】:2016-07-13 08:51:56
【问题描述】:

我需要使用| 分隔符将字符串36-3031.00|36-3021.00 标记为36-3031.0036-3021.00

我试过这样,

PUT text
{
   "test1": {
  "settings": {
    "analysis" : {
            "tokenizer" : {
                "pipe_tokenizer" : {
                    "type" : "pattern",
                    "pattern" : "|"
                }
            },
            "analyzer" : {
                "pipe_analyzer" : {
                    "type" : "custom",
                    "tokenizer" : "pipe_tokenizer"
                }
            }
        }
  },
  "mappings": {
    "mytype": {
      "properties": {
        "text": {
          "type": "string",
          "analyzer": "pipe_analyzer"
        }
      }
    }
  }
}}

但它不会产生精确的结果。任何人都可以整理出这个用例吗?

【问题讨论】:

    标签: elasticsearch tokenize


    【解决方案1】:

    以下是您应该使用的正确映射(包括 REST PUT 命令中的索引名称)。并且| 字符需要转义:

    DELETE test1
    PUT test1
    {
      "settings": {
        "analysis": {
          "tokenizer": {
            "pipe_tokenizer": {
              "type": "pattern",
              "pattern": "\\|"
            }
          },
          "analyzer": {
            "pipe_analyzer": {
              "type": "custom",
              "tokenizer": "pipe_tokenizer"
            }
          }
        }
      },
      "mappings": {
        "mytype": {
          "properties": {
            "text": {
              "type": "string",
              "analyzer": "pipe_analyzer"
            }
          }
        }
      }
    }
    
    POST /test1/mytype/1
    {"text":"36-3031.00|36-3021.00"}
    
    GET /test1/_analyze
    {"field":"text","text":"36-3031.00|36-3021.00"}
    

    【讨论】:

    • GET /test1/_analyze { "field": "productID", "text": "36-3031.00|36-3021.00" } 拆分为 36, 3031.00, 36, 3021.00
    • 那说明你没有完全按照我的指示去做。我已经通过完整的测试更新了我的答案。
    猜你喜欢
    • 1970-01-01
    • 2014-06-06
    • 2021-06-28
    • 1970-01-01
    • 1970-01-01
    • 2020-05-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多