es - elasticsearch mapping - parameters - search_analyzer

·  阅读 116

世界上并没有完美的程序,但是我们并不因此而沮丧,因为写程序就是一个不断追求完美的过程。

问 :search_analyzer有什么特点?
答 :
在这里插入图片描述

问 :search_analyzer如何使用?
答 :

# search_analyzer
PUT /search_analyzer_test
{
  "settings" : {
    "analysis" : {
      "filter" : {
        "autocomplete_filter" : {
          "type"     : "edge_ngram",
          "min_gram" : 1,
          "max_gram" : 20
        }
      },
      "analyzer" : {
        "autocomplete" : {
          "type"      : "custom",
          "tokenizer" : "standard",
          "filter"    : [
            "lowercase", 
            "autocomplete_filter"
          ]
        }
      }
    }
  },
  "mappings" : {
    "properties" : {
      "name" : {
        "type"            : "text",
        "analyzer"        : "autocomplete",
        "search_analyzer" : "standard"
      }
    }
  }
}

# 索引
POST /search_analyzer_test/_doc/1
{
  "name" : "hello good me"
}

# 搜索, 由于索引阶段使用了edge_ngram, 索引搜索阶段可以对词部分搜索
GET /search_analyzer_test/_search
{
  "query" : {
    "match" : {
      "name" : "hell"
    }
  }
}

# 结果
{
  "took" : 183,
  "timed_out" : false,
  "_shards" : {
    "total" : 1,
    "successful" : 1,
    "skipped" : 0,
    "failed" : 0
  },
  "hits" : {
    "total" : {
      "value" : 1,
      "relation" : "eq"
    },
    "max_score" : 0.4095239,
    "hits" : [
      {
        "_index" : "search_analyzer_test",
        "_type" : "_doc",
        "_id" : "1",
        "_score" : 0.4095239,
        "_source" : {
          "name" : "hello good me"
        }
      }
    ]
  }
}
复制代码
分类:
后端
标签:
收藏成功!
已添加到「」, 点击更改