elasticsearch简单操作

查看所有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": "系统" } }
      ]
    }
  }
}'
posted @ 2019-05-20 17:01  wswang  阅读(247)  评论(0编辑  收藏  举报