How to identify a document Elasticsearch-

ES- identification document

In order to identify the same index of an article documents, ES _uid used in combination of ID and document type. by the _id field _uid and _type fields when searching or retrieving documents always get these two pieces of information.

FengZhendeMacBook-Pro:cv FengZhen$ curl -XGET 'localhost:9200/music/album/5?pretty&fields'
{
"_index" : "music",
"_type" : "album",
"_id" : "5",
"_version" : 1,
"found" : true
}

Since all documents are in the same Lucene index, ES internal use _uid to uniquely determine the identity document. Separating type and ID of an abstract, by distinguishing the type of operation makes it easier for different configurations. Because of this, _id usually extracted from _uid out, but _type must separate index, so when searching for a particular type, the system can easily be filtered according to document type.

_uid: 
  whether to store: yes 
  whether the index: yes 
  Description: document identification for a piece of the entire index 
the _id: 
  whether to store: no 
  whether the index: no 
  Description: This field is not indexed, nor stored. If you search for him, actually using a _uid. When the results were obtained, too, it is to extract content from _uid. 
_type: 
  whether to store: no 
  whether the index: no_analyzed 
  Description: This field is indexed, and generates a single entry. ES filter use it to specify the type of document. You can also search the field


1. Provide a document ID

(1) manually specify

So far, the majority is provided by a portion of the ID manually URI. For example, to index for the 1st ID document, run a command like this

FengZhendeMacBook-Pro:cv FengZhen$ curl -XPUT 'localhost:9200/get-together/manual_id/1st?pretty' -d '{
> "name":"Elasticsearch Denver"
> }'
{
"_index" : "get-together",
"_type" : "manual_id",
"_id" : "1st",
"_version" : 1,
"_shards" : {
"total" : 2,
"successful" : 1,
"failed" : 0
},
"created" : true
}

(2) ES generated automatically

ES can rely on to generate a unique ID. If there is no a unique ID, or there is no need to identify the documents by a particular property, it would be helpful. In general, when the log index application would do: These data are not the only attributes to identify them, but they also never been updated.
In order for ES generation ID, and eliminates the use of an HTTP POST request ID

FengZhendeMacBook-Pro:cv FengZhen$ curl -XPOST 'localhost:9200/logs/auto_id/?pretty' -d '{
> "message":"test es auto id"
> }'
{
"_index" : "logs",
"_type" : "auto_id",
"_id" : "AWut3pFctSp-KrHOt_--",
"_version" : 1,
"_shards" : {
"total" : 2,
"successful" : 1,
"failed" : 0
},
"created" : true
}

Automatic reply can be seen in ID: AWut3pFctSp-KrHOt _--

2. In the document to store the index name

In addition to ID and type, in order to allow ES to store the index name in a document, you can use _index field. And _id, _type, as can be seen in search results or GET request in _index, it is not derived from the contents of the field.
ES know what each result from the index, so it can show the value of _index

FengZhendeMacBook-Pro:cv FengZhen$ curl 'localhost:9200/_search?q=_index:get-together&pretty'

{

  "took" : 3,

  "timed_out" : false,

  "_shards" : {

    "total" : 25,

    "successful" : 25,

    "failed" : 0

  },

  "hits" : {

    "total" : 1,

    "max_score" : 1.0,

    "hits" : [ {

      "_index" : "get-together",

      "_type" : "manual_id",

      "_id" : "1st",

      "_score" : 1.0,

      "_source" : {

        "name" : "Elasticsearch Denver"

      }

    } ]

  }

}

Guess you like

Origin www.cnblogs.com/EnzoDin/p/11117412.html