admin 管理员组文章数量: 887021
2024年1月5日发(作者:linux基础及应用)
查询语句GET test2/doc/_search{“query”: {“match_phrase_prefix”: {“desc”: “bea”}}}查询结果(){“took” : 5,“timed_out” : false,“_shards” : {“total” : 5,“successful” : 5,“skipped” : 0,“failed” : 0},“hits” : {“total” : 2,“max_score” : 0.39556286,“hits” : [{“_index” : “test2”,“_type” : “doc”,“_id” : “1”,“_score” : 0.39556286,“_source” : {“title” : “prefix1”,“desc” : “beautiful girl you are beautiful so”}},{“_index” : “test2”,“_type” : “doc”,“_id” : “2”,“_score” : 0.2876821,“_source” : {“title” : “beautiful”,“desc” : “I like basking on the beach”}}]}}
GET test2/doc/_search{“query”: {“multi_match”: {“query”: “beautiful”,“fields”: [“title”,“desc”]}}}查询结果{“took” : 43,“timed_out” : false,“_shards” : {“total” : 5,“successful” : 5,“skipped” : 0,“failed” : 0},“hits” : {“total” : 2,“max_score” : 0.39556286,“hits” : [{“_index” : “test2”,“_type” : “doc”,“_id” : “1”,“_score” : 0.39556286,“_source” : {“title” : “prefix1”,“desc” : “beautiful girl you are beautiful so”}},{“_index” : “test2”,“_type” : “doc”,“_id” : “2”,“_score” : 0.2876821,“_source” : {“title” : “beautiful”,“desc” : “I like basking on the beach”}}]}}当设置属性 type:phrase 时 等同于 短语查询
GET test/doc/_search{“query”: {“bool”: {“should”: [{“match”: {“name”: “wangjifei”}},{“match”: {“age”: 27}}]}}}
GET w1/doc/_search{“query”: {“match”: {“t2”: “hi”}}}GET w1/doc/_search{“query”: {“match”: {“t2”: “hi single dog”}}}t1类型为text,会经过分词,term查询时条件不会经过分词,所以只有当值为"hi"时能查询到GET w1/doc/_search{“query”: {“term”: {“t1”: “hi single dog”}}}GET w1/doc/_search{“query”: {“term”: {“t1”: “hi”}}}t2类型为keyword类型,不会经过分词,term查询时条件不会经过分词,所以只能当值为"hisingle dog"时能查询到GET w1/doc/_search{“query”: {“term”: {“t2”: “hi single dog”}}}
GET zhifou/doc/_search{“query”: {“match”: {“from”: “gu”}},“aggs”: {“my_avg”: {“avg”: {“field”: “age”}}},“_source”: [“name”, “age”]}
GET zhifou/doc/_search{“query”: {“match_all”: {}},“aggs”: {“my_min”: {“min”: {“field”: “age”}}},“size”: 0,“_source”: [“name”,“age”,“from”]}查询结果{“took” : 2,“timed_out” : false,“_shards” : {“total” : 5,“successful” : 5,“skipped” : 0,“failed” : 0},“hits” : {“total” : 5,“max_score” : 0.0,“hits” : [ ]},“aggregations” : {“my_min” : {“value” : 18.0}}}需求4、查询符合条件的年龄之和
GET zhifou/doc/_search{“size”: 0,“query”: {“match_all”: {}},“aggs”: {“age_group”: {“range”: {“field”: “age”,“ranges”: [{“from”: 15,“to”: 20},{“from”: 20,“to”: 25},{“from”: 25,“to”: 30}]}}}}
GET zhifou/doc/_search{“size”: 0,“query”: {“match_all”: {}},“aggs”: {“age_group”: {“range”: {“field”: “age”,“ranges”: [{“from”: 15,“to”: 20},{“from”: 20,“to”: 25},{“from”: 25,“to”: 30}]},“aggs”: {“my_avg”: {“avg”: {“field”: “age”}}}}}}
GET test4/_mapping查询结果{“test4” : {“mappings” : {“doc” : {“properties” : {“age” : {“type” : “long”},“name” : {“type” : “text”},“sex” : {“type” : “text”,“fields” : {“keyword” : {“type” : “keyword”,“ignore_above” : 256}}}}}}}}#####添加数据PUT test4/doc/1{“name”:“wangjifei”,“age”:“18”,“sex”:“不详”}#####查看数据GET test4/doc/_search{“query”: {“match_all”: {}}}
查询结果{“took” : 8,“timed_out” : false,“_shards” : {“total” : 5,“successful” : 5,“skipped” : 0,“failed” : 0},“hits” : {“total” : 1,“max_score” : 1.0,“hits” : [{“_index” : “test4”,“_type” : “doc”,“_id” : “1”,“_score” : 1.0,“_source” : {“name” : “wangjifei”,“age” : “18”,“sex” : “不详”}}]}}测试静态映射:当elasticsearch察觉到有新增字段时,因为dynamic:false的关系,会忽略该字段,但是仍会存储该字段。#####创建静态mappingPUT test5{“mappings”: {“doc”:{“dynamic”:false,“properties”: {“name”: {“type”: “text”},“age”: {“type”: “long”}}}}}
查询结果{“error”: {“root_cause”: [{“type”: “query_shard_exception”,“reason”: “failed to create query: {n “match” : {n “age” : {n “query” : 18,n “operator” :“OR”,n “prefix_length” : 0,n “max_expansions” : 50,n “fuzzy_transpositions” : true,n “lenient” :false,n “zero_terms_query” : “NONE”,n “auto_generate_synonyms_phrase_query” : true,n “boost”: 1.0n }n }n}”,“index_uuid”: “fzN9frSZRy2OzinRjeMKGA”,“index”: “test7”}],“type”: “search_phase_execution_exception”,“reason”: “all shards failed”,“phase”: “query”,“grouped”: true,“failed_shards”: [{“shard”: 0,“index”: “test7”,“node”: “INueKtviRpO1dbNWngcjJA”,“reason”: {“type”: “query_shard_exception”,“reason”: “failed to create query: {n “match” : {n “age” : {n “query” : 18,n “operator” :“OR”,n “prefix_length” : 0,n “max_expansions” : 50,n “fuzzy_transpositions” : true,n “lenient” :false,n “zero_terms_query” : “NONE”,n “auto_generate_synonyms_phrase_query” : true,n “boost”: 1.0n }n }n}”,“index_uuid”: “fzN9frSZRy2OzinRjeMKGA”,“index”: “test7”,“caused_by”: {“type”: “illegal_argument_exception”,“reason”: “Cannot search on field [age] since it is not indexed.”}}}]},“status”: 400}5. ES 之 mappings 的copy_to属性
版权声明:本文标题:超全的elasticsearch查询语句语法大全 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.freenas.com.cn/jishu/1704441077h459939.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论