添加结构
1.首先创建索引使用POST
2.在使用http://170.160.230.26:9200/ppst/_mapping?pretty
{
"properties": {
"author": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword"
}
}
},
"content": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword"
}
}
},
"id": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword"
}
}
},
"postdate": {
"type": "date"
},
"title": {
"type": "text",
"fields": {
"keyword": {
"type": "text",
"analyzer": "ik_max_word" ,//指定分词器
"search_analyzer": "ik_max_word"
}
}
}
}
}
2.安装好分词器验证(PS所有查询都是PSOT请求)
http://172.16.23.206:9200/_analyze 利用postman或者其他工具请求头用json
对这个进行分词
{
"analyzer": "ik_smart",
"text": "王者荣耀"
}
分词结果
{
"tokens": [
{
"token": "王者",
"start_offset": 0,
"end_offset": 2,
"type": "CN_WORD",
"position": 0
},
{
"token": "荣耀",
"start_offset": 2,
"end_offset": 4,
"type": "CN_WORD",
"position": 1
}
]
}
GET /ppst/_doc/_search?pretty
{
"query": {
"wildcard": {
"title": {
"value": "*设计*"
}
}
}
}
{
"query":{
"term":{
"title":"北京奥运"
}
}
}
//-------------------------------------
//----------单字段查询-----------------
http://172.16.23.206:9200/ppst/_doc/_search
{
"query": {
"match": {
"title": "设计"
}
},
"size": 2,
"from": 0,
"highlight": {
"fields" : {
"title" : {}
}
}
}
http://172.16.23.206:9200/ppst/_doc/_search
{
"query": {
"multi_match" : {
"query" : "设计PHP",
"fields": ["title", "content"]
}
}
}
{"_id":"8Edhv20BXaQgVz1212pi"}
{
"_index": "poem",
"_type": "poem",
"_id": "AOTmyW0Bz28OxJZgSr-s",
"_version": 1,
"_score": 1,
"_source": {
"id": "",
"author": "柳宗元",
"title": "晨诣超师院读禅经",
"content": "汲井漱寒齿,清心拂尘服。 闲持贝叶书,步出东斋读。 真源了无取,忘迹世所逐。 遗言冀可冥,缮性何由熟? 道人庭宇静,苔色连深竹。 日出雾露馀,青松如膏沐。 澹然离言说,悟悦心自足。",
"postdate": "2018-02-03"
}
}
{
"id": "29",
"title": "程序开发设计思想",
"content": "程序要必懂",
"postdate": "2018-02-03"
}
删除请求用DELETE
http://172.16.23.206:9200/blog/blog/8Edhv20BXaQgVz1212pi?pretty
修改,添加。请求用POST没有就创建有就更新
http://172.16.23.206:9200/blog/blog/8Edhv20BXaQgVz1212pi?pretty
传输的数据(要修改的字段)
{
"id": "100",
"title": "JS开发设计思想",
"content": "程序要必懂",
"postdate": "2018-02-03"
}