.添加索引和类型,同时设定edgengram分词和charsplit分词

时间:2022-05-26 10:35:34

1.添加索引和类型,同时设定edgengram分词和charsplit分词

curl -XPUT 'http://127.0.0.1:9200/userindex/' -d

'{

  "settings": {

    "index": {

      "analysis": {

        "analyzer": {

          "charsplit": {

            "tokenizer": "my_ngram_tokenizer"

          },

          "edgengram": {

            "tokenizer": "my_edge_ngram_tokenizer"

          }

        },

        "tokenizer": {

          "my_ngram_tokenizer": {

            "token_chars": [

              "letter",

              "digit"

            ],

            "min_gram": "1",

            "type": "nGram",

            "max_gram": "1"

          },

          "my_edge_ngram_tokenizer": {

            "token_chars": [

              "letter",

              "digit"

            ],

            "min_gram": "2",

            "type": "edgeNGram",

            "max_gram": "5"

          }

        }

      },

      "number_of_shards": "5",

      "number_of_replicas": "1",

      "uuid": "gbT6I5puQH2LhzPJmv13fg",

      "version": {

        "created": "2010199"

      }

    }

  },

  "mappings": {

    "userinfo": {

      "properties": {

        "address": {

          "analyzer": "edgengram",

          "type": "string"

        },

        "address2": {

          "include_in_all": false,

          "analyzer": "charsplit",

          "type": "string"

        },

        "username": {

          "type": "string",

          "analyzer": "standard"

        }

      }

    }

  }

}'

2.添加一条记录

curl -XPUT 'http://172.16.58.82:9200/userindex/userinfo/1/'

'{

"address": "good morning anting 靠近昆山",

"address2": "anting你好 在安亭附近",

"username": "james 你好"

}

'

3.查询

{

"query": {

"match_phrase_prefix": {

"address": {

"query": "good morn",

"analyzer": "edgengram"

}

}

}

}

查询见下图:

.添加索引和类型,同时设定edgengram分词和charsplit分词