Spec-Zone.ru › Elasticsearch 8
›Elasticsearch Guide [8.17] ›Mapping ›Поля метаданных

Поле _id

Каждый документ имеет _id, который однозначно его идентифицирует и индексируется, чтобы документы можно было найти с помощью API GET или ids запроса. _id можно присвоить во время индексирования, или Elasticsearch может сгенерировать уникальное _id. Это поле не настраивается в картах.

Значение поля _id доступно в запросах, таких как term, terms, match и query_string.

resp = client.index(
    index="my-index-000001",
    id="1",
    document={
        "text": "Document with ID 1"
    },
)
print(resp)

resp1 = client.index(
    index="my-index-000001",
    id="2",
    refresh=True,
    document={
        "text": "Document with ID 2"
    },
)
print(resp1)

resp2 = client.search(
    index="my-index-000001",
    query={
        "terms": {
            "_id": [
                "1",
                "2"
            ]
        }
    },
)
print(resp2)
response = client.index(
  index: 'my-index-000001',
  id: 1,
  body: {
    text: 'Document with ID 1'
  }
)
puts response

response = client.index(
  index: 'my-index-000001',
  id: 2,
  refresh: true,
  body: {
    text: 'Document with ID 2'
  }
)
puts response

response = client.search(
  index: 'my-index-000001',
  body: {
    query: {
      terms: {
        _id: [
          '1',
          '2'
        ]
      }
    }
  }
)
puts response
{
	res, err := es.Index(
		"my-index-000001",
		strings.NewReader(`{
	  "text": "Document with ID 1"
	}`),
		es.Index.WithDocumentID("1"),
		es.Index.WithPretty(),
	)
	fmt.Println(res, err)
}

{
	res, err := es.Index(
		"my-index-000001",
		strings.NewReader(`{
	  "text": "Document with ID 2"
	}`),
		es.Index.WithDocumentID("2"),
		es.Index.WithRefresh("true"),
		es.Index.WithPretty(),
	)
	fmt.Println(res, err)
}

{
	res, err := es.Search(
		es.Search.WithIndex("my-index-000001"),
		es.Search.WithBody(strings.NewReader(`{
	  "query": {
	    "terms": {
	      "_id": [
	        "1",
	        "2"
	      ]
	    }
	  }
	}`)),
		es.Search.WithPretty(),
	)
	fmt.Println(res, err)
}
const response = await client.index({
  index: "my-index-000001",
  id: 1,
  document: {
    text: "Document with ID 1",
  },
});
console.log(response);

const response1 = await client.index({
  index: "my-index-000001",
  id: 2,
  refresh: "true",
  document: {
    text: "Document with ID 2",
  },
});
console.log(response1);

const response2 = await client.search({
  index: "my-index-000001",
  query: {
    terms: {
      _id: ["1", "2"],
    },
  },
});
console.log(response2);
# Example documents
PUT my-index-000001/_doc/1
{
  "text": "Document with ID 1"
}

PUT my-index-000001/_doc/2?refresh=true
{
  "text": "Document with ID 2"
}

GET my-index-000001/_search
{
  "query": {
    "terms": {
      "_id": [ "1", "2" ] 
    }
  }
}

Запрос к полю _id (также см. ids запрос)

Поле _id ограничено для использования в агрегациях, сортировке и сценариях. Если требуется сортировка или агрегация по полю _id, рекомендуется дублировать содержимое поля _id в другое поле, для которого включена doc_values.

Размер поля _id ограничен 512 байтами, значения больше этого размера будут отклонены.

© 2023-2025 Elasticsearch
As of September 2024, Elasticsearch is available under a choice of three licenses: the Server Side Public License (SSPL), the Elastic License, or the AGPLv3 (OSI approved).
Elasticsearch and the Elasticsearch logo are trademarks of Elasticsearch B.V., registered in the U.S. and in other countries.
https://www.elastic.co/guide/en/elasticsearch/reference/8.17/mapping-id-field.html

Spec-Zone.ru

Настройки Оффлайн Что нового Помощь О нас
Spec-Zone .ru
спецификации, руководства, описания, API