https://www.elastic.co/guide/en/elasticsearch/reference/6.4/multi-index.html
multi index
映射/数据字段类型
1.别名数据类型
https://www.elastic.co/guide/en/elasticsearch/reference/6.4/alias.html
在搜索请求的某些部分,当请求字段功能时,可以提供字段通配符模式。在这些例子中,通配符模式将匹配除具体字段之外的字段别名:
GET trips/_field_caps?fields=route_*,transit_mode
返回:
{
"fields" : {
"transit_mode" : {
"keyword" : {
"type" : "keyword",
"searchable" : true,
"aggregatable" : true
}
},
"route_length_miles" : {
"keyword" : {
"type" : "keyword",
"searchable" : true,
"aggregatable" : true
}
}
}
}
别名目标
用做别名的目标有一些限制:
- 目标必须是具体的字段,不能是一个对象或者其他别名字段。
- 当别名被创建时,目标字段必须存在。
- 如果定义了嵌套对象,字段别名必须与其目标有相同的嵌套范围。
额外的,一个字段别名仅可以有一个目标。这意味着在一个语句中无法使用别名字段查询多个目标字段。
不支持的 API
对别名字段的写入是不支持的:企图通过索引中的别名字段去更新请求会导致失败。同样的,别名字段也无法用在 copy_to
或者是多字段中。
因为别名的名字并不会出现在文档的 source 中,它也不可以被用做字段过滤。如,下面的请求将会返回一个空的 _source
:
GET /_search
{
"query" : {
"match_all": {}
},
"_source": "route_length_miles"
}
目前仅有查询和 field capabilities
接受并解析别名。其他 API 接受字段名字,例如 term vectors,无法使用字段别名。
最后,类似于 terms
,geo_shape
,more_like_this
,这样的查询,允许通过索引文档获取查询信息。因为字段别名不支持获取文档,指定查找路径的部分查询不能通过别名引用字段。
索引重建
reindex
curl 请求时长
curl -o /dev/null -s -w ‘%{time_connect}:%{time_starttransfer}:%{time_total}’ -XPOST
update by query
{
“script”: {
“source”: “ctx._source.catnode=’/hello’”,
“lang”: “painless”
},
“query”: {
“term”: {
“catnode”: “/e45r2t40b/e45r3f2vr”
}
}
}
sql 插件使用
GET /_sql/_explain/?sql=select * from index where _id = 2
GET /_sql?sql=select * from index/employ limit 10
curl -XPOST "http://127.0.0.1:9200/_xpack/sql/translate?pretty" -H 'Content-Type: application/json' -d'
{
"query":"SELECT * FROM idx where step = 'aaa' limit 20"
}'
POST /_xpack/sql/translate
{
“query”:”select aid from assid where aid = ‘a’ or aid = ‘b’”
}
"must": {
"exists": {
"field": "per_condition"
}
{
"query":{
"exists": {
"field": "typedata.3"
}
}
}
{
“from”: 0,
“size”: 0,
“query”: {
“bool”: {
“filter”: [
{
“bool”: {
“must”: [
{
“match_phrase”: {
“ver”: {
“query”: “aaa”,
“slop”: 0,
“zero_terms_query”: “NONE”,
“boost”: 1
}
}
}
],
“adjust_pure_negative”: true,
“boost”: 1
}
}
],
“adjust_pure_negative”: true,
“boost”: 1
}
},
“aggregations”: {
“aid”: {
“terms”: {
“field”: “aid”,
“size”: 200,
“min_doc_count”: 1,
“shard_min_doc_count”: 0,
“show_term_doc_count_error”: false,
“order”: [
{
“_count”: “desc”
},
{
“_key”: “asc”
}
]
}
}
}
}
{
“sort”: {
“utime”: {
“order”: “desc”
}
},
“size”: 0,
“query”: {
“match”: {
“content”: “article”
}
},
“aggs”: {
“value”: {
“terms”: {
“field”: “aid”,
“order”: {
“_key”: “asc”
},
“size”: 2
},
“aggs”: {
“value”: {
“top_hits”: {
“sort”: [
{
“utime”: {
“order”: “desc”
}
}
],
“size”: 100,
“_source”: {
“includes”: [
“ver”,
“content”
]
}
}
}
}
}
}
}
get _scripts
{
“size”: 0,
“query”: {
“match”: {
“content”: “article”
}
},
“aggs”: {
“group_by”: {
“terms”: {
“field”: “aid”,
“order”: {
“_key”: “asc”
},
“size”: 2
}
}
}
}
get _scripts
{
“size”: 0,
“query”: {
“bool”: {
“must”: [
{
“match”: {
“content”: “article”
}
}
]
}
},
“aggs”: {
“value”: {
“terms”: {
“field”: “aid”,
“size”: 2
},
“aggs”: {
“value”: {
“terms”: {
“field”: “step”,
“size”: 2
},
“aggs”: {
“value”: {
“top_hits”: {
“size”: 100,
“_source”: true
}
}
}
}
}
}
}
}
GET index
{
“size”: 0,
“query”: {
“bool”: {
“must”: [
{
“match”: {
“content”: “article”
}
}
]
}
},
“aggs”: {
“value”: {
“terms”: {
“field”: “aid”,
“size”: 2
},
“aggs”: {
“value”: {
“terms”: {
“field”: “step”
},
“top_hits”: {
“size”: 100,
“_source”: true
}
}
}
}
}
}
get /_sql/_explain?sql=select distinct aid from assid
{
“from”: 0,
“size”: 0,
“query”: {
“bool”: {
“filter”: [
{
“bool”: {
“must”: [
{
“bool”: {
“must”: [
{
“bool”: {
“should”: [
{
“match_phrase”: {
“aid
“: {
“query”: “7IOUBbhPg5O”,
“slop”: 0,
“boost”: 1
}
}
},
{
“match_phrase”: {
“aid
“: {
“query”: “7IOUs7uEHn2”,
“slop”: 0,
“boost”: 1
}
}
},
{
“match_phrase”: {
“aid
“: {
“query”: “7IOWjNPgASc”,
“slop”: 0,
“boost”: 1
}
}
}
],
“adjust_pure_negative”: true,
“boost”: 1
}
},
{
“bool”: {
“must”: [
{
“script”: {
“script”: {
“source”: “1 == 1”,
“lang”: “painless”
},
“boost”: 1
}
}
],
“adjust_pure_negative”: true,
“boost”: 1
}
}
],
“adjust_pure_negative”: true,
“boost”: 1
}
}
],
“adjust_pure_negative”: true,
“boost”: 1
}
}
],
“adjust_pure_negative”: true,
“boost”: 1
}
},
“sort”: [
{
“aid”: {
“order”: “asc”
}
}
],
“aggs”: {
“group_by_aid”: {
“terms”: {
“field”: “aid”
},
“aggs”: {
“value”: {
“top_hits”: {
“_source”: {
“includes”: [
“content”,
“ver”
]
}
}
}
}
}
}
}
{
“from”: 0,
“size”: 10,
“query”: {
“bool”: {
“filter”: [
{
“bool”: {
“must”: [
{
“bool”: {
“must”: [
{
“match_phrase”: {
“creator”: {
“query”: “e15h7deixt2”,
“slop”: 0,
“boost”: 1
}
}
},
{
“bool”: {
“should”: [
{
“match_phrase”: {
“catnode”: {
“query”: “/“,
“slop”: 0,
“boost”: 1
}
}
}
],
“adjust_pure_negative”: true,
“boost”: 1
}
}
],
“adjust_pure_negative”: true,
“boost”: 1
}
}
],
“adjust_pure_negative”: true,
“boost”: 1
}
}
],
“adjust_pure_negative”: true,
“boost”: 1
}
},
“sort”: [
{
“utime”: {
“order”: “desc”
}
}
],
“_source”: false,
“collapse”: {
“field”: “aid”
},
“aggs”: {
“unique”: {
“cardinality”: {
“field”: “aid”
}
}
}
}