Elastic 的分词器称为 analyzer 。我们对每个字段指定分词器。
- "user": {
- "type": "text",
- "analyzer": "ik_max_word",
- "search_analyzer": "ik_max_word"
- }
膳绫擎代铝闼楝 analyzer 是字段文本的分词器, search_analyzer 是搜刮词典分词器。 ik_max_word 分词器是插件 ik 供给的,可以对文本进行最大年夜数量的分词。
五、数据操作
5.1 新增记录
向指定的 /Index/Type 发送 PUT 请求,就可以在 Index 琅绫擎新增一笔记录。比如,向 /accounts/person 发送请求,就可以新增一条人员记录。
- $ curl -X PUT 'localhost:9200/accounts/person/1' -d '
- {
- "user": "张三",
- "title": "工程师",
- "desc": "数据库治理"
- }'
办事器返回的 JSON 对象,会给出 Index、Type、Id、Version 等信息。
- {
- "_index":"accounts",
- "_type":"person",
- "_id":"1",
- "_version":1,
- "result":"created",
- "_shards":{"total":2,"successful":1,"failed":0},
- "created":true
- }
如不雅你细心看,会发明请求路径是 /accounts/person/1 ,最后的 1 是该笔记录的 Id。它不必定是数字,随便率性字符串(比如 abc )都可以。
新增记录的时刻,也可以不指定 Id,这时要改成 POST 请求。
- $ curl -X POST 'localhost:9200/accounts/person' -d '
- {
- "user": "李四",
- "title": "工程师",
- "desc": "体系治理"
- }'
膳绫擎代铝闼楝向 /accounts/person 发出一个 POST 请求,添加一个记录。这时,办事器返回的 JSON 对象琅绫擎, _id 字段就是一个随机字符串。

网友点评
精彩导读
科技快报
品牌展示