zoukankan      html  css  js  c++  java
  • 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": "系统" } }
          ]
        }
      }
    }'
  • 相关阅读:
    Class 'ViewCell' has no initializers
    xcode:关于Other Linker Flags
    NSString编码形式是UTF–16
    手写识别方案汇总
    将一个 view 进行截图
    程序员最核心的竞争力是什么?
    sqlite3
    创建NAT 64网络
    Snagit安装步骤
    cnblogs插件jiathis
  • 原文地址:https://www.cnblogs.com/wswang/p/10895133.html
Copyright © 2011-2022 走看看