主页 >> 程序猿的东西 >> elasticsearch查询速记

elasticsearch查询速记

# 所有别名
GET _aliases
# 别名结尾是online的索引
get /_alias/*online

# 别名对应的索引
GET /_alias/strategy_case_discard

# 批量设置别名  add  remove
POST /_aliases
{
    "actions" : [
        { "add" : { "index" : "example", "alias" : "online" } }
    ]
}

# user对象查询
GET /test/_search
{
  "query": {
    "term": {
      "user.user_id": {
        "value": "211977"
      }
    }
  }
}

# 字段是否存在
GET /test/_search
{
  "query": {
    "exists": {
        "field": "vip"
    }
  }
}

# 分词器调试
GET /test/_analyze
{
    "text":"卡缤美学家居",
    "analyzer":"ik_max_syno"
}

# _source 控制输出字段
GET /test/_search
{
  "query": {},
  "_source": {
    "includes": [
      "user_id",
      "user_name",
      "match_id",
      "tags_str",
      "user_tags_str",
      "user_tags_str_all",
      "topic_tags_str",
      "content"
    ]
  },
  "from": 0,
  "size": 100
}

# 阿里云推荐配置
PUT _settings
{
        "index.indexing.slowlog.threshold.index.debug" : "10ms",
        "index.indexing.slowlog.threshold.index.info" : "50ms",
        "index.indexing.slowlog.threshold.index.warn" : "100ms",
        "index.search.slowlog.threshold.fetch.debug" : "100ms",
        "index.search.slowlog.threshold.fetch.info" : "200ms",
        "index.search.slowlog.threshold.fetch.warn" : "500ms",
        "index.search.slowlog.threshold.query.debug" : "100ms",
        "index.search.slowlog.threshold.query.info" : "200ms",
        "index.search.slowlog.threshold.query.warn" : "1s"
}

PUT _template/aliyun-slowlog_template
{
    "order": -1,
    "version": 0,
    "template": "*",
    "settings": {
        "index.indexing.slowlog.threshold.index.debug" : "10ms",
        "index.indexing.slowlog.threshold.index.info" : "50ms",
        "index.indexing.slowlog.threshold.index.warn" : "100ms",
        "index.search.slowlog.threshold.fetch.debug" : "100ms",
        "index.search.slowlog.threshold.fetch.info" : "200ms",
        "index.search.slowlog.threshold.fetch.warn" : "500ms",
        "index.search.slowlog.threshold.query.debug" : "100ms",
        "index.search.slowlog.threshold.query.info" : "200ms",
        "index.search.slowlog.threshold.query.warn" : "1s"
    }
}

发表评论