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"

        }

    }

}'


本文转自whk66668888 51CTO博客,原文链接:http://blog.51cto.com/12597095/1903495


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值