fsfss21 发表于 2017-3-6 13:47:49

elasticsearch 前缀匹配

curl -XDELETE 'http://localhost:9200/ess/';
curl -XPOST 'http://localhost:9200/ess' -d '{
      "analysis": {
            "filter": {
                "autocomplete_filter": {
                  "type":   "edge_ngram",
                  "min_gram": 1,
                  "max_gram": 20,
"token_chars": ["whitespace"]
                }
            },
            "analyzer": {
                "autocomplete": {
                  "type":      "custom",
                  "tokenizer": "whitespace",
                  "filter": [
                        "lowercase",
                        "autocomplete_filter"
                  ]
                },
"postsearch": {
                   "tokenizer": "keyword",
   "filter": [
                        "lowercase"
                  ]
                }
            }
      }

}'



curl -XPOST 'http://localhost:9200/ess/ess/_mapping' -d'
{
    "ess": {

      "properties": {
      "id": {
          "type" : "long"
      },
      "fullname": {
          "type" : "string"
      },
      "allname": {
          "type" : "string",
          "analyzer":"autocomplete",
          "search_analyzer": "postsearch"
      }

      }
      }
}'




curl 'localhost:9200/ess/_analyze?pretty=1&analyzer=autocomplete' -d 'zs zhangsan zsan zhangs 张三 张s zns'

curl 'localhost:9200/ess/_analyze?pretty=1&analyzer=postsearch' -d 'Z'

curl -XPOST http://localhost:9200/ess/ess/1 -d'
{"fullname":"张三" , "allname" : "zs zhangsan zsan zhangs 张三 张s zns" }
'

curl -XPOST http://localhost:9200/ess/ess/2 -d'
{"fullname":"张三风" , "allname" : "zsf zhangsanfeng zsanfeng zhangsf 张三 三风 张sf znsf" }
'

curl -XPOST http://localhost:9200/ess/ess/3 -d'
{"fullname":"李三风" , "allname" : "lsf lisanfeng lsanfeng lsf 李三 三风 李s lsf" }
'


curl -XGET 'http://localhost:9200/ess/_search?pretty' -d '{
   "query": {
      "match": {
            "allname": "张S"
      }
    }
}'


页: [1]
查看完整版本: elasticsearch 前缀匹配