ElasticSearch之Doc结构中常规操作(新增字段、查询数据)

背景:

腾讯云上的ElasticSearch服务,操作客户端:Kibana

1.在ES中指定doc_field_name内部新增字段的指令:

PUT es_index_name/_mapping/${doc_field_name}
{
  "properties":{
    "newFieldName" : {
      "type" : "integer"
    }
  }
}

备注:其中”es_index_name“为索引名称;

2.查询指定doc路径下的信息:

# 查询索引的配置
get es_index_name/_settings

# 查询索引的内部doc结构
get es_index_name/_mapping

# 可以带查询条件的搜索---指定查询字段,精确匹配
GET es_index_name/_search
{
  "query": {
    "term": {
      "doc_field_name": {
        "value": "doc_field_value"
      }
    }
  }
}

# 可以带查询条件的搜索---多条件查询,精确匹配
GET es_index_name/_search
{
  "query": {
    "bool": {
      "filter": [
      {
        "term": {
           "field_name_1": 1
         }
      },
      {
        "term": {
           "field_name_2": 1
         }
      }
      ]
    }
  }
}

# 可以带查询条件的搜索---更复杂的多条件查询,支持分页和排序
GET es_index_name/_search
{
    "from": 0,
    "size": 20,
    "timeout": "60s",
    "query": {
        "bool": {
            "filter": [
                {
                    "term": {
                        "field_name_1": {
                            "value": "field_name_1_value",
                            "boost": 1.0
                        }
                    }
                },
                {
                    "terms": {
                        "field_name_2": [
                            "field_name_2_value"
                        ],
                        "boost": 1.0
                    }
                },
                {
                    "range": {
                        "field_name_3_int": {
                            "from": 1400,
                            "to": null,
                            "include_lower": true,
                            "include_upper": true,
                            "boost": 1.0
                        }
                    }
                },
                {
                    "range": {
                        "field_name_4_int": {
                            "from": null,
                            "to": 3500,
                            "include_lower": true,
                            "include_upper": true,
                            "boost": 1.0
                        }
                    }
                }
            ],
            "must_not": [
                {
                    "terms": {
                        "field_name_5_int": [
                            -1,
                            99
                        ],
                        "boost": 1.0
                    }
                }
            ],
            "adjust_pure_negative": true,
            "boost": 1.0
        }
    },
    "sort": [
        {
            "field_name_6": {
                "order": "desc"
            }
        },
        {
            "field_name_7": {
                "order": "desc"
            }
        }
    ]
}

 

posted @ 2024-05-29 10:33  OutPointException  阅读(94)  评论(0编辑  收藏  举报