Elasticsearch 查询

 查看索引列表: http://127.0.0.1:9200/_cat/indices?v

------------恢复内容开始------------

 查看索引列表: http://127.0.0.1:9200/_cat/indices?v

新建索引:put  http://127.0.0.1:9200/shopping

新建内容 :post http://127.0.0.1:9200/shopping/_doc

新建定义ID数据: post http://127.0.0.1:9200/shopping/_doc/id

查询所有:get http://127.0.0.1:9200/shopping/_search

覆盖内容: put http://127.0.0.1:9200/shopping/_doc/id

局部更新:post http://127.0.0.1:9200/shopping/_update/1001

     {

         "doc":{

            "title":"华为手机"

         }

    } 

条件查询

查询索引总条数

GET /vehicle/_count
{
}

  get   http://127.0.0.1:9200/shopping/_search?q=category:小米

   get http://127.0.0.1:9200/shopping/_search

    局部查询    {

           "query":{

                "match":{

                   "category":"小米"

              }

           }

     }

模糊查询

GET vehicle/_search
{
"query":{
   "wildcard":{
        "vlpncolor.keyword":{
            "value":"*01*"
          }
     }
   }
}

 

 精准查询

GET vehicle/_search
{
  "track_total_hits":true,
  "query": {
        "bool": {
               "must": [
                     { "term": { "vlpn.keyword": "测YG3146" }},
                    { "term": { "vlpncolor.keyword": "01" } }
              ]
           }
      }
}

 

   全量查询   

  {

           "query":{

                "match_all ":{

              }

           },

          "from":0,

          "size":2,

          "_source":["title"],   //返回列

          "sort":{

               "price":{

                    "order":"desc"

               }

          }

        }

多条件查询,范围查询

{

  "query":{

       "bool":{

          "must":[  //多条件满足    should  //单条件满足

               {

            "match":{

                 "category":"小米"

               }

            }

       ],

      "filter":{

         "range":{

             "price":{

                 "gt":5000

            }

         }   

    }

     }

  }

}

全文匹配,完全匹配,高亮匹配

{

"query":{

  "match_phrase":{

     " category":"xx"

  }

},

"highlight":{

  "fields":{

   "category":{}

 }

}

}

聚合查询

{

  "aggs":{

      "price_group":{   // price_avg

            "terms":{   //avg

               "field":"price"

           }

       }

    },

   "size":0

}

 

GET /vehicle/_search
{
     "size" : 0,
          "aggs" : {
             "popular_colors" : {
               "terms" : {
                    "field" : "attention"
                }
           }
    }
}

 

 

映射关系

get  http://127.0.0.1:9200/user/_mapping

{

  "properties":{

      "name":{

             "type":"text",
              "index":true   //可被索引查询

    },

   "sex":{

             "type":"keyword",  //非模糊查询
              "index":false   //不可被索引查询

    }

}

 

}

 

//索引增加字段

PUT vehicle/_mapping/_doc?include_type_name=true
  {
       "properties": {
              "VehicleID": {
                 "type": "long"
              }
   }
  }

 

------------恢复内容结束------------

posted @   不再犯错  阅读(68)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· SQL Server 2025 AI相关能力初探
· AI编程工具终极对决:字节Trae VS Cursor,谁才是开发者新宠?
· 开源Multi-agent AI智能体框架aevatar.ai,欢迎大家贡献代码
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
点击右上角即可分享
微信分享提示