1.下载和es相同版本的ik分词器,elasticsearch-analysis-ik-8.2.0

2.elasticsearch-analysis-ik-8.2.0.zip在es的plugins文件下解析

3.重启es

4.查看分词效果

POST _analyze
{
  "analyzer": "ik_smart",
  "text": "我爱我的钱"
}

POST _analyze
{
  "analyzer": "ik_max_word",
  "text": "你的钱是我的"
}

5.创建带有中文分词器的索引

PUT xzqh1
{
  "mappings": {
  "properties": {
    "code": {
      "type": "text","index":true
    },
    "name": {
      "type": "text","index":true,
      "analyzer": "ik_max_word"
    },
    "level": {
      "type": "text","index":true
    },
    "pcode": {
      "type": "text","index":true
    },
    "TENANT_ID_": {
      "type": "text","index":true
    },
    "pname": {
      "type": "text","index":true,  "analyzer": "ik_max_word"
    }
  }
  }
}

6.查询命令

term取得是交集
match取得的是并集。

GET /xzqu/_search
{
  "query": {
    "match": {
      "name": "崂山区"
    }
  }
}

GET /xzqu/_search
{
  "query": {
    "term": {
      "name": "金"
    }
  }
}

 

Logo

为开发者提供学习成长、分享交流、生态实践、资源工具等服务,帮助开发者快速成长。

更多推荐