亲,只收二进制

ES拼音全拼搜索

Elasticsearch | 作者 Xiaoming | 发布于2018年02月26日 | 阅读数:5717

如果有两个词,天命和明天,我期望用拼音搜索如:输入mingtian,结果为明天排除天命.然而现在这俩结果全部返回.
 
mapping 
PUT /search_text
{
"settings":{
"refresh_interval":"5s",
"number_of_shards":1,
"number_of_replicas":1,
"analysis":{
"filter":{
"edge_ngram_filter":{
"type":"edge_ngram",
"min_gram":1,
"max_gram":50
},
"pinyin_full_filter":{
"type" : "pinyin",
"keep_first_letter":false,
"keep_separate_first_letter" : false,
"keep_full_pinyin" : true,
"keep_original" : false,
"limit_first_letter_length" : 50,
"lowercase" : true
},
"pinyin_simple_filter":{
"type" : "pinyin",
"keep_first_letter":true,
"keep_separate_first_letter" : false,
"keep_full_pinyin" : false,
"keep_original" : false,
"limit_first_letter_length" : 50,
"lowercase" : true
}
},
"analyzer":{
"pinyiSimpleIndexAnalyzer": {
"type": "custom",
"tokenizer": "keyword",
"filter": [
"pinyin_simple_filter",
"edge_ngram_filter",
"lowercase"
]
},
"pinyiFullIndexAnalyzer":{
"type":"custom",
"tokenizer" : "keyword",
"filter": ["pinyin_full_filter","lowercase"]
}
}
}
}
}

PUT /search_text/_mapping/list
{
"properties":{
"name":{
"type":"keyword",
"fields":{
"fpy":{
"type":"text",
"index":true,
"analyzer":"pinyiFullIndexAnalyzer"
},
"spy": {
"type": "text",
"index":true,
"analyzer" : "pinyiSimpleIndexAnalyzer"
}
}
}
}

}

 
插入数据:
PUT /search_text/list/1
{
"name":"明天你好"
}
PUT /search_text/list/2
{
"name":"天命"
}
PUT /search_text/list/3
{
"name":"你好明天"
}

 
搜索测试:
POST /search_text/list/_search
{
  "query":{
      "match":{
          "name.fpy":{
              "query":"mingtian",
              "operator": "and"
          }
      }
  }
}

结果:
{
"took": 0,
"timed_out": false,
"_shards": {
"total": 1,
"successful": 1,
"failed": 0
},
"hits": {
"total": 3,
"max_score": 0.29506737,
"hits": [
{
"_index": "search_text",
"_type": "list",
"_id": "2",
"_score": 0.29506737,
"_source": {
"name": "天命"
}
},
{
"_index": "search_text",
"_type": "list",
"_id": "1",
"_score": 0.24686475,
"_source": {
"name": "明天你好"
}
},
{
"_index": "search_text",
"_type": "list",
"_id": "3",
"_score": 0.24686475,
"_source": {
"name": "你好明天"
}
}
]
}
}

而期望的应该是匹配明天,不是天命 ,或者即使匹配到了天命也应该排到最后,求指点
已邀请:

rockybean - Elastic Certified Engineer, ElasticStack Fans,公众号:ElasticTalk

赞同来自:

你用 _analyze 接口看下实际分词的结果应该就明白了
 
https://www.elastic.co/guide/e ... .html

hufuman

赞同来自:

should里加一个match_phrase用来加分

要回复问题请先登录注册