檢視所有index
curl -X GET 'localhost:9200/_cat/indices?v'
檢視每個index所有的type
curl 'localhost:9200/_mapping?pretty=true'
建立index
curl -X PUT 'localhost:9200/weather'
删除index
curl -X DELETE 'localhost:9200/weather'
建立index并指定要分詞的字段(accounts是index,person是type,person有三個字段)
curl -X PUT 'localhost:9200/accounts' -d '
{
"mappings": {
"person": {
"properties": {
"user": {
"type": "text",
"analyzer": "ik_max_word",
"search_analyzer": "ik_max_word"
},
"title": {
"type": "text",
"analyzer": "ik_max_word",
"search_analyzer": "ik_max_word"
},
"desc": {
"type": "text",
"analyzer": "ik_max_word",
"search_analyzer": "ik_max_word"
}
}
}
}
}'
index裡新增document
curl -X PUT 'localhost:9200/accounts/person/1' -d '
{
"user": "張三",
"title": "工程師",
"desc": "資料庫管理"
}'
檢視記錄
curl 'localhost:9200/accounts/person/1?pretty=true'
删除記錄
curl -X DELETE 'localhost:9200/accounts/person/1'
檢視所有記錄
curl 'localhost:9200/accounts/person/_search'
查找(通過from和size指定位移,分頁操作)
curl 'localhost:9200/accounts/person/_search' -d '
{
"query" : { "match" : { "desc" : "管理" }},
"from": 1,
"size": 1
}'
多個關鍵字搜尋(or)
curl 'localhost:9200/accounts/person/_search' -d '
{
"query" : { "match" : { "desc" : "管理" }},
"from": 1,
"size": 1
}'
多個關鍵詞搜尋(and)
curl 'localhost:9200/accounts/person/_search' -d '
{
"query": {
"bool": {
"must": [
{ "match": { "desc": "軟體" } },
{ "match": { "desc": "系統" } }
]
}
}
}'