首页 > 其他 > 详细

ES-常用操作

时间:2021-04-07 21:06:03      阅读:31      评论:0      收藏:0      [点我收藏+]
1.查询
1.GET /index-name/_search/
{
  "query": {
    "bool": {
      "filter": [
        {
          "range": {
            "dt": {
              "gte": "20191112",
              "lte": "20191112",
              "format": "yyyyMMdd",
              "time_zone": "+08:00"
            }
          }
        }
      ],
      "must":[
      {
        "match_phrase":{
            "user_name":""
        }
      }
      ]
    }
  }
}

2.GET /index-name/_search/
{"query":{"bool":{"filter":[{"term":{"feed_id":{"value":"6810658570879700237","boost":1.0}}}],"adjust_pure_negative":true,"boost":1.0}}}

2.更新字段值

1.POST /index-name/all/docId/_update
{
  "doc":{
          "word" : "[{‘word‘:‘笑死‘,‘count‘:‘7.0‘},{‘word‘:‘笑‘,‘count‘:‘7.0‘}]"
        }
}

2.POST /index-name/all/docId/_update
{
    "doc":{
        "music_name" : "原声"
    }
}

3.删除索引

DELETE index-name

4.通过url查询数据

查看所有索引:
http://10.2.3.101:9200/_cat/indices
查看docId=‘517588130509981824‘的数据信息:
http://10.2.3.101:9200/index-name/all/517588130509981824

5.设置字段类型

PUT /index-name
{
    "mappings": {
      "all": {
        "properties": {
            "feed_id": {
              "type": "keyword"
            },
            "user_id": {
              "type": "keyword"
            },
            "comment_feed_id": {
              "type": "keyword"
            },
            "comment_feed_content":{
              "type": "text",
              "analyzer":"ik_max_word",
              "search_analyzer":"ik_max_word"
            },
            "create_time":{
              "type": "keyword"
            },
            "key":{
              "type": "keyword"
            },
            "dt":{
              "type": "keyword"
            }
          }
        }
    }
}

6.更新字段类型

ES不能更新映射,要想更新映射,只能数据迁移
例如:索引bank的字段age类型long更新为integer
1.创建一个新索引 
PUT /newbank
{
    "mappings": {
        "properties": {
            "age": {
              "type": "integer"
            },
            "name": {
              "type": "text"
            },
            "mail": {
              "type": "keyword"
            }
         }
    }
}
2.查看新索引的映射:
GET /newbank/_mapping
3.数据迁移
POST _reindex
{
    "source":{
        "index":"bank"
    },
    "dest":{
        "index":"newkank"
    }
}
如果指定了类型:
POST _reindex
{
    "source":{
        "index":"bank"
        "type":"account"
    },
    "dest":{
        "index":"newkank"
    }
}

7.分词

按照空格将每个单词分割

POST _analyze
{
    "analyzer":"standard",
    "text":"The 2 quick Brown-Foxes jumped the dog‘s bone."
}

8.查看相关性评分详情

GET /index-name/all/517588130509981824/_explain
{
  "query":{
    "bool":{
      "must":{"match":{"user_id":"517588130509981824"}}
    }
  }
}

 

ES-常用操作

原文:https://www.cnblogs.com/mn-lily/p/14628139.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!