• Elasticsearch常用操作api


    1、查看所有Index
    curl -X GET 'http://localhost:9200/_cat/indices?v'

    2、查看每个Index下的type
    curl 'localhost:9200/_mapping?pretty=true'

    3、创建索引,且指定分词器ik
    curl -H "Content-Type: application/json" -XPUT "http://localhost:9200/cmsdb_test" -d '
    {
    "settings": {
    "index": {
    "analysis.analyzer.default.type": "ik_smart" //智能分词
    "analysis.analyzer.default.type": "ik_max_word" //最细分词
    }
    }
    }'

    4、新增一条数据 (put需要制定id,用post不需要制定id)
    curl -X PUT 'localhost:9200/accounts/person/1' -d '
    {
    "user": "张三",
    "title": "工程师",
    "desc": "数据库管理"
    }'
    curl -X POST 'localhost:9200/accounts/person' -d '
    {
    "user": "李四",
    "title": "工程师",
    "desc": "系统管理"
    }'

    5、查看某一条记录
    curl 'localhost:9200/accounts/person/1?pretty=true'

    6、删除某一条记录
    curl -X DELETE 'localhost:9200/accounts/person/1'

    7、更新一条记录
    curl -X PUT 'localhost:9200/accounts/person/1' -d '
    {
    "user" : "张三",
    "title" : "工程师",
    "desc" : "数据库管理,软件开发"
    }'

    8、查询某type下所有数据
    curl 'localhost:9200/accounts/person/_search'

    9、match查询并设置高亮字段
    curl 'localhost:9200/accounts/person/_search' -d '
    {
    "query" : { "match" : { "desc" : "软件" }}
    "highlight": {
    "pre_tags": [
    "<font color='red'>"
    ],
    "post_tags": [
    "</font>"
    ],
    "fields": {
    "desc" {}
    }
    }
    }'

    10、查询所有字段包含某个词
    curl -XGET 'localhost:9200/accounts/person/_search' -d '
    {
    "query": {
    "multi_match": {
    "query": "习xxx",
    "fields": [
    "title"
    ]
    }
    }
    }'

    11、设置某个字段的权重,并设置返回的字段
    curl -XGET 'localhost:9200/accounts/person/_search' -d '
    {
    "query": {
    "multi_match" : {
    "query" : "elasticsearch guide",
    "fields": ["name", "title^3"]
    }
    },
    "_source": ["name", "summary", "title"]
    }'

    12、布尔查询 must=and,should=or,must_not=not
    curl -XGET 'localhost:9200/accounts/person/_search' -d '
    {
    "query": {
    "bool": {
    "must": {
    "bool" : { "should": [
    { "match": { "title": "Elasticsearch" }},
    { "match": { "title": "Solr" }} ] }
    },
    "must": { "match": { "authors": "clinton gormely" }},
    "must_not": { "match": {"authors": "radu gheorge" }}
    }
    }
    }'

    13、模糊度查询(Fuzzy Queries)
    curl -XGET 'localhost:9200/accounts/person/_search' -d '
    {
    "query": {
    "multi_match" : {
    "query" : "comprihensiv guide",
    "fields": ["title", "summary"],
    "fuzziness": "AUTO"
    }
    },
    "_source": ["title", "summary", "publish_date"],
    "size": 1
    }'

    14、通配符查询(Wildcard Query)
    curl -XGET 'localhost:9200/accounts/person/_search' -d '
    {
    "query": {
    "wildcard" : {
    "authors" : "t*"
    }
    },
    "_source": ["title", "authors"],
    "highlight": {
    "fields" : {
    "authors" : {}
    }
    }
    }'

    15、正则表达式查询(Regexp Query)
    curl -XGET 'localhost:9200/accounts/person/_search' -d '
    {
    "query": {
    "regexp" : {
    "authors" : "t[a-z]*y"
    }
    },
    "_source": ["title", "authors"],
    "highlight": {
    "fields" : {
    "authors" : {}
    }
    }
    }'

    16、匹配短语查询(Match Phrase Query) (key,"title","sub_title","lead_title","summary","keyword","article_tag","source","author","editor","liability","content")
    curl -XGET 'localhost:9200/accounts/person/_search' -d '
    {
    "query": {
    "multi_match": {
    "query": "search engine",
    "fields": [
    "title",
    "summary"
    ],
    "type": "phrase",
    "slop": 3 //控制输入的trems之间有多少个单词仍然能够搜索到
    }
    },
    "_source": [
    "title",
    "summary",
    "publish_date"
    ]
    }'

  • 相关阅读:
    element-ui实现表格el-table展开行
    jQuery请求本地JSON文件,在谷歌浏览器运行时报跨域错误
    jQuery使用serialize获取form表单数据,中文乱码问题
    Element-ui局部添加loading效果
    Vue中this.$set的使用
    项目管理【81】 | 项目立项管理
    项目管理【80】 | 知识产权与标准规范-标准规范
    项目管理【79】 | 知识产权与标准规范-政府采购法法
    项目管理【78】 | 知识产权与标准规范-招投标法
    项目管理【77】 | 知识产权与标准规范-合同法
  • 原文地址:https://www.cnblogs.com/helloemk/p/9771457.html
Copyright © 2020-2023  润新知