elasticsearch中的字母数字全文搜索

时间:2016-05-12 14:27:14

标签: elasticsearch

PUT employee
{
    "settings": {
        "index": {
            "analysis": {
                "tokenizer" : {
                    "my_edge_ngram_tokenizer" : {
                        "type" : "edgeNGram",
                        "min_gram" : "2",
                        "max_gram" : "10",
                        "token_chars": [ "letter", "digit" ]                            
                    }
                },
                "analyzer": {
                    "data_Analyzer": {
                        "filter": [
                        "lowercase"
                        ],
                        "type": "custom",
                        "tokenizer": "my_edge_ngram_tokenizer"
                    }
                }
            },
            "mappings": {
                "employee": {
                    "properties": {
                        "groupId": {
                            "type": "long",
                            "index": "no"
                        }
                        "displayId": {
                            "type": "string",
                            "analyzer": "data_Analyzer"
                        }                       
                    }
                }
            }
        }
    }
}

我们有以下组合的数据

1)groupId:1,displayId:E0SZ5D8 2)groupId:1,displayId:E0FS4ED 3)groupId:1,displayId:1234567 4)groupId:1,displayId:EJKDSHS 5)groupId:2,displayId:..... 6)groupId:2,displayId:.....

使用以下弹性查询:

GET /employee/_search
{
  "query": {
    "bool": {
      "must": [
        {
          "term": {
            "groupId": {
              "value": 1
            }
          }
        }
      ],
      "minimum_number_should_match": 1,
      "should": [
        {
          "match": {
            "displayId": {
              "query": "E0SZ5D8",
              "type": "boolean"
            }
          }
        }
      ]
    } 
  }
}

返回的数据匹配 E0SZ5D8,E0FS4ED

当我们看到 explain:true 时。

它将搜索文本标记剥离为:E0,E0S,S,5,D8,8 ...但不是整个字符串“E0SZ5D8”

因为我正在寻找一个完全匹配(类型:布尔值)它不应该返回所有,但应该只有匹配“E0SZ5D8”的结果

0 个答案:

没有答案