ElasticSearch学习

文章40 |   阅读 24264 |   点赞0

来源:https://blog.csdn.net/ywl470812087/category_9621251.html

ElasticSearch(中文检索)source总结

x33g5p2x  于2021-12-19 转载在 其他  
字(3.1k)|赞(0)|评价(0)|浏览(536)

包含不包含这里不多讲了。 

GET /lib4/user/_search
{
  "query": {
    "match_all": {}
  },
  "_source": {
    "includes": ["name" ,"address"],
    "excludes": ["age" , "birthday" ]
  }
}

直接看看结果

{
  "took" : 5,
  "timed_out" : false,
  "_shards" : {
    "total" : 3,
    "successful" : 3,
    "skipped" : 0,
    "failed" : 0
  },
  "hits" : {
    "total" : 5,
    "max_score" : 1.0,
    "hits" : [
      {
        "_index" : "lib4",
        "_type" : "user",
        "_id" : "2",
        "_score" : 1.0,
        "_source" : {
          "address" : "北京海淀区清河",
          "name" : "赵明"
        }
      },
      {
        "_index" : "lib4",
        "_type" : "user",
        "_id" : "4",
        "_score" : 1.0,
        "_source" : {
          "address" : " 北京海淀区清河",
          "name" : "王五"
        }
      },
      {
        "_index" : "lib4",
        "_type" : "user",
        "_id" : "5",
        "_score" : 1.0,
        "_source" : {
          "address" : "北京海淀区清河",
          "name" : "张三"
        }
      },
      {
        "_index" : "lib4",
        "_type" : "user",
        "_id" : "1",
        "_score" : 1.0,
        "_source" : {
          "address" : "黑龙江省 铁岭",
          "name" : "赵六"
        }
      },
      {
        "_index" : "lib4",
        "_type" : "user",
        "_id" : "3",
        "_score" : 1.0,
        "_source" : {
          "address" : "北京海淀区清河",
          "name" : "lisi"
        }
      }
    ]
  }
}
GET /lib4/user/_search
{
  "_source": {
    "includes": "addr*" ,
    "excludes": ["name", "bir*"]
  },
  "query": {
    "match_all": {}
  }
}



#查询结果
{
  "took" : 2,
  "timed_out" : false,
  "_shards" : {
    "total" : 3,
    "successful" : 3,
    "skipped" : 0,
    "failed" : 0
  },
  "hits" : {
    "total" : 5,
    "max_score" : 1.0,
    "hits" : [
      {
        "_index" : "lib4",
        "_type" : "user",
        "_id" : "2",
        "_score" : 1.0,
        "_source" : {
          "address" : "北京海淀区清河"
        }
      },
      {
        "_index" : "lib4",
        "_type" : "user",
        "_id" : "4",
        "_score" : 1.0,
        "_source" : {
          "address" : " 北京海淀区清河"
        }
      },
      {
        "_index" : "lib4",
        "_type" : "user",
        "_id" : "5",
        "_score" : 1.0,
        "_source" : {
          "address" : "北京海淀区清河"
        }
      },
      {
        "_index" : "lib4",
        "_type" : "user",
        "_id" : "1",
        "_score" : 1.0,
        "_source" : {
          "address" : "黑龙江省 铁岭"
        }
      },
      {
        "_index" : "lib4",
        "_type" : "user",
        "_id" : "3",
        "_score" : 1.0,
        "_source" : {
          "address" : "北京海淀区清河"
        }
      }
    ]
  }
}

sort排序

GET /lib4/user/_search
{
  "query": {
    "match_all": {} 
  },
  "sort": {
     "age": {"order":"asc"}
  }
}

相关文章