#查看索引配置信息#
GET /test_index/_settings
#1.数据准备#
PUT user_index
{
"settings": {
"number_of_replicas": 0,
"number_of_shards": 3
},
"mappings": {
"properties": {
"name": {
"type": "text"
},
"address": {
"type": "text"
},
"age": {
"type": "integer"
},
"interests": {
"type": "text"
},
"birthday": {
"type": "date"
}
}
}
}
GET /user_index
#2.插入数据#
POST /user_index/_doc/1
{
"name":"lisi",
"address":"shandong",
"age":18,
"interests":"youyong shufa changge tiaowu",
"birthday":"2001-01-19"
}
POST /user_index/_doc/2
{
"name": "wangwu",
"address": "zhejiang",
"age": 22,
"interests": "youyong shufa",
"birthday": "1997-01-19"
}
POST /user_index/_doc/3
{
"name": "zhangsan",
"address": "zhejiang",
"age": 20,
"interests": "youyong shufa changge changpao",
"birthday": "1999-08-29"
}
POST /user_index/_doc/6
{
"name": "youyong",
"address": "zhejiang",
"age": 22,
"interests": "youyong shufa changge changpao",
"birthday": "1999-08-29"
}
#精确查询#
GET /user_index/_search?q=name:youyong
GET /user_index/_search?q=name:youyong&sort=age:desc
#term查询和terms查询:term query去倒排索引中找到确切的term,不知道分词器的存在,适合keyword,date,numetic,是包含(contains操作),不是等值(equals)判断#
GET /user_index/_doc/_search
{
"query":{
"term":{
"interests":"changpao"
}
}
}
GET /user_index/_doc/_search
{
"query":{
"terms":{
"interests":["youyong","shufa"]
}
}
}
#查询控制返回的数量#
GET /user_index/_search
{
"from": 0,
"size": 2,
"query": {
"terms": {
"interests": [
"shufa",
"youyong"
]
}
}
}
#返回版本号,版本号是啥???
GET /user_index/_search
{
"version": true,
"from": 0,
"size": 2,
"query": {
"terms": {
"interests": [
"shufa",
"youyong"
]
}
}
}
#match查询,知道分词器的存在,对filed会进行分词操作,再查询
#单字段查询 match
GET user_index/_search
{
"query": {
"match": {
"age": 20
}
}
}
GET user_index/_search
{
"query": {
"match": {
"interests": "changge"
}
}
}
#指定多字段查询 multi_match
GET user_index/_search
{
"query": {
"multi_match": {
"query": "youyong",
"fields": ["interests","name"]
}
}
}
#短语匹配查询
GET user_index/_search
{
"query": {
"match_phrase": {
"interests": "shufa changge"
}
}
}
#查询全部
GET /user_index/_search/
{
"query": {
"match_all": {}
}
}
#指定返回的字段
GET /user_index/_search
{
"_source": ["name","age"],
"query":{
"match": {
"interests": "changge"
}
}
}
#指定需要的字段,去除不要的字段,可使用通配符
GET /user_index/_search
{
"query": {
"match_all": {}
},
"_source": {
"includes": "addr*",
"excludes": ["name","dir*"]
}
}
#排序
#前缀匹配查询,并使用sort排序:desc:降序,asc:升序
GET /user_index/_search
{
"query": {
"match_phrase_prefix": {
"interests": "you"
}
},
"sort": [
{
"age": {
"order": "desc"
}
}
]
}
# range范围查询,参数 from,to,include_lower是否包含范围左边界,include_upper是否包含范围右边界,boost
GET /user_index/_search
{
"query": {
"range": {
"birthday": {
"gte": "1990-10-10",
"lte": "2000-05-01"
}
}
}
}
#wildcard查询,允许通配符 * 和?来查询; * 代表0个或多个字符, ? 代表任意一个字符
GET /user_index/_search
{
"query": {
"wildcard": {
"name": {
"value": "wang*"
}
}
}
}
# fuzzy 模糊查询,与term查询的模糊等价,是包含(contains)操作,不是等值(equals)操作,不知道分词器的存
GET /user_index/_search
{
"query": {
"fuzzy": {
"interests": "shuf"
}
}
}
# 删除单个:
DELETE /index
curl -XDELETE http://192.169.1.666:9200/index
#你也可以这样删除多个索引:
DELETE /index_one,index_two
curl -XDELETE http://192.169.1.666:9200/index_one,index_two
DELETE /index_*
curl -XDELETE http://192.169.1.666:9200/index_*
ES | ES 查询命令
最后编辑于 :
©著作权归作者所有,转载或内容合作请联系作者
- 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
- 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
- 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
推荐阅读更多精彩内容
- 项目中的es查询需求需要查询多种多样的文本,并且根据一系列的条件进行过滤。而es如何去构建复杂的多条件查询呢? 1...
- 内容简介 1.spring整合es2.普通查询的使用方法3.聚合查询的使用方法4.普通查询与聚合查询的使用区别 s...