1、安装elasticsearch6.2.4、elasticsearch-head、postman
2、对于elasticsearch中的索引(index)、类型(type)、文档(document)、域(field)、映射(mapping)等的理解
3、熟悉常用的4中请求方式,符合restful规则。get(请求查询)、post(修改请求)、put(增加索引)、delete(删除索引)
以下为postman工具请求
#创建blog索引并指定相应的mapping,如果当创建索引之后没有指定索引或者想修改索引使用POST
PUT http://127.0.0.1:9200/blog { "mappings": { "article": { "properties": { "id": { "type":"long", "store":true }, "title": { "type":"text", "store":true, "index":true, "analyzer":"standard" }, "content": { "type":"text", "store":true, "index":true, "analyzer":"standard" } } } } }
#对article类型创建新的属性 POST http://127.0.0.1:9200/blog/article
{ "mappings": { "article": { "properties": { "id": { "type":"long", "store":true }, "title": { "type":"text", "store":true, "index":true, "analyzer":"standard" }, "content": { "type":"text", "store":true, "index":true, "analyzer":"standard" } } } } }
#向blog索引中类型为article的_id为1的文档中添加信息
POST http://127.0.0.1:9200/blog/article/1 { "id": "001", "title": "博客COPY_", "content": "elasticsearch搜索关键词详解" } { "_index": "blog", "_type": "article", "_id": "1", "_version": 4, "result": "updated", "_shards": { "total": 2, "successful": 1, "failed": 0 }, "_seq_no": 3, "_primary_term": 1 }
#一下使用query_string请求,进行分词,elasticsearch默认是一个中文是一个关键词,当进行普通查询时{"query":{"term":{"name":"无"}}}
POST http://127.0.0.1:9200/blog/article/_search { "query": { "query_string": { "default_field": "title", "query": "今天进入博客园" } } } { "took": 18, "timed_out": false, "_shards": { "total": 5, "successful": 5, "skipped": 0, "failed": 0 }, "hits": { "total": 1, "max_score": 0.5753642, "hits": [ { "_index": "blog", "_type": "article", "_id": "1", "_score": 0.5753642, "_source": { "title": "博客COPY_" } } ] } }
#默认分词器分词效果(不同版本可能测试方式不一样,)
#http://localhost:9200/_analyze?analyzer=stardand&text=开发人员 #版本不同以至于出现如下错误 { "error": { "root_cause": [ { "type": "parse_exception", "reason": "request body or source parameter is required" } ], "type": "parse_exception", "reason": "request body or source parameter is required" }, "status": 400 }
GET http://127.0.0.1:9200/_analyze? { "analyzer": "standard", "text": "何以报仇,在我学子" } { "tokens": [ { "token": "何", "start_offset": 0, "end_offset": 1, "type": "<IDEOGRAPHIC>", "position": 0 }, { "token": "以", "start_offset": 1, "end_offset": 2, "type": "<IDEOGRAPHIC>", "position": 1 }, { "token": "报", "start_offset": 2, "end_offset": 3, "type": "<IDEOGRAPHIC>", "position": 2 }, { "token": "仇", "start_offset": 3, "end_offset": 4, "type": "<IDEOGRAPHIC>", "position": 3 }, { "token": "在", "start_offset": 5, "end_offset": 6, "type": "<IDEOGRAPHIC>", "position": 4 }, { "token": "我", "start_offset": 6, "end_offset": 7, "type": "<IDEOGRAPHIC>", "position": 5 }, { "token": "学", "start_offset": 7, "end_offset": 8, "type": "<IDEOGRAPHIC>", "position": 6 }, { "token": "子", "start_offset": 8, "end_offset": 9, "type": "<IDEOGRAPHIC>", "position": 7 } ] }
原文:https://www.cnblogs.com/ffzzcommsoft/p/11905708.html