Elasticsearch整理之Meta-Fields

1. _index

文档所属的索引。https://www.elastic.co/guide/en/elasticsearch/reference/6.3/mapping-source-field.html

2. _id

每个文档都有一个独一的id标识它,id可用于特定的查询 (termtermsmatchquery_stringsimple_query_string).

PUT my_index/_doc/1
{
  "text": "Document with ID 1"
}

PUT my_index/_doc/2
{
  "text": "Document with ID 2"
}

GET my_index/_search
{
  "query": {
    "terms": {
      "_id": [ "1","2" ] 
    }
  }
}

3. _source

存储了原始的文档。若要关闭,须将enabled属性设为false。但是,如果关闭_source,那么下面的功能将不再支持

      (1)update、update_by_query、reindex

      (2)使用高亮

      (3)改变索引、改变mapping、升级索引

4. _field_names

5. _routing

ES使用下面的公式计算文档被放到哪个分片上

shard_num = hash(_routing) % num_primary_shards

_routing的默认值是文档的_id,可以通过设置_routing来设置自定义路由。下面的代码使用user1作为路由值,在GET数据时也要使用路由值

PUT my_index/_doc/1?routing=user1&refresh=true 
{
  "title": "This is a document"
}

GET my_index/_doc/1?routing=user1 
GET my_index/_search
{
  "query": {
    "terms": {
      "_routing": [ "user1" ] 
    }
  }
}

GET my_index/_search?routing=user1,user2 
{
  "query": {
    "match": {
      "title": "document"
    }
  }
}

当需要使用自定义路由时,为了保险起见,需将_routing设为required,这样CRUD操作都要指定路由否则会报错

PUT my_index2
{
  "mappings": {
    "_doc": {
      "_routing": {
        "required": true 
      }
    }
  }
}

// 抛出路由缺失异常
PUT my_index2/_doc/1
{
  "text": "No routing value provided"
}

6. _meta

https://www.elastic.co/guide/en/elasticsearch/reference/6.3/mapping-meta-field.html

 

你可能感兴趣的:(elasticsearch)