Elasticsearchノート-004-ドキュメントAPI-CRUD-単一ドキュメント検索操作
6015 ワード
[toc]
output:
id=2のドキュメントが存在しないことがわかります.
ドキュメントが更新されたが、まだリフレッシュされていない場合、get APIは、ドキュメントを表示するためのリフレッシュコールを発行します.デフォルトでは、get APIはリアルタイムであり、インデックスのリフレッシュレートの影響を受けない.(もちろんrealtime GETを無効にすることもでき、realtimeパラメータをfalseに設定することもできます.)
デフォルトでは、get操作は無効にしない限りsourceコンテンツを返します.ソースフィールド:
無効:
ソースの1つまたは2つのフィールドのみを使用する場合は、 _source_includesは検索したいだけsourceノードのuserフィールドとmessageフィールド: _sourceの上記の内容は、以下のように簡単に書くことができます.source source_excludesは除外したいsourceノードのmessageフィールド、残りの全表示:
使用/{index}/source/{id}ドキュメントのみ取得ソースフィールドには、追加の内容は含まれません.例:
純粋なデータのみが返されることがわかります.上の_も使えますソースのフィルタフィールド:
デフォルトでは、フィールド値は検索可能にインデックスされますが、元の値は保存されません.これは、フィールドを調べることができますが、元のフィールド値を取得することはできません.例:
索引レコード:
クエリ
すべて調べることができます;stored_の使用fieldsパラメータクエリー:
counterフィールドがなくなりました.mappingには
単一ドキュメントget API
1.Get基本クエリー
GET weibo/_doc/1
output:
{
"_index" : "weibo",
"_type" : "_doc",
"_id" : "1",
"_version" : 3,
"_seq_no" : 2,
"_primary_term" : 1,
"found" : true,
"_source" : {
"user" : "niewj",
"post_date" : "2009-11-15T14:12:12",
"message" : "trying out Elasticsearch"
}
}
2.headクエリードキュメントが存在するかどうか
GET weibo/_doc/2
結果:{
"_index" : "weibo",
"_type" : "_doc",
"_id" : "2",
"found" : false
}
id=2のドキュメントが存在しないことがわかります.
HEAD weibo/_doc/2
結果:404 - Not Found
文書id=1は存在する:GET weibo/_doc/1
の結果:{
"_index" : "weibo",
"_type" : "_doc",
"_id" : "1",
"_version" : 3,
"_seq_no" : 2,
"_primary_term" : 1,
"found" : true,
"_source" : {
"user" : "niewj",
"post_date" : "2009-11-15T14:12:12",
"message" : "trying out Elasticsearch"
}
}
HEAD
で照会:HEAD weibo/_doc/1
、結果:200 - OK
HEAD:調べられない:404;検出:200;3.getクエリーインデックスのリアルタイム性
ドキュメントが更新されたが、まだリフレッシュされていない場合、get APIは、ドキュメントを表示するためのリフレッシュコールを発行します.デフォルトでは、get APIはリアルタイムであり、インデックスのリフレッシュレートの影響を受けない.(もちろんrealtime GETを無効にすることもでき、realtimeパラメータをfalseに設定することもできます.)
4. \ _ソースの無効化
デフォルトでは、get操作は無効にしない限りsourceコンテンツを返します.ソースフィールド:
GET weibo/_doc/1
: {
"_index" : "weibo",
"_type" : "_doc",
"_id" : "1",
"_version" : 3,
"_seq_no" : 2,
"_primary_term" : 1,
"found" : true,
"_source" : {
"user" : "niewj",
"post_date" : "2009-11-15T14:12:12",
"message" : "trying out Elasticsearch"
}
}
無効:
GET weibo/_doc/1?_source=false
:{
"_index" : "weibo",
"_type" : "_doc",
"_id" : "1",
"_version" : 3,
"_seq_no" : 2,
"_primary_term" : 1,
"found" : true
}
5. \_sourceフィールドのフィルタリング(excludes/includes)
ソースの1つまたは2つのフィールドのみを使用する場合は、
_source_include
パラメータと_source_exclude
パラメータを使用して、次のパラメータを含むかフィルタできます.GET weibo/_doc/1?_source_includes=user,message
{
"_index" : "weibo",
"_type" : "_doc",
"_id" : "1",
"_version" : 3,
"_seq_no" : 2,
"_primary_term" : 1,
"found" : true,
"_source" : {
"message" : "trying out Elasticsearch",
"user" : "niewj"
}
}
GET weibo/_doc/1?_source=user,message
GET weibo/_doc/1?_source_excludes=message
{
"_index" : "weibo",
"_type" : "_doc",
"_id" : "1",
"_version" : 3,
"_seq_no" : 2,
"_primary_term" : 1,
"found" : true,
"_source" : {
"post_date" : "2009-11-15T14:12:12",
"user" : "niewj"
}
}
6.直接使用ソース取得データ
使用/{index}/source/{id}ドキュメントのみ取得ソースフィールドには、追加の内容は含まれません.例:
GET weibo/_source/1
{
"user" : "niewj",
"post_date" : "2009-11-15T14:12:12",
"message" : "trying out Elasticsearch"
}
純粋なデータのみが返されることがわかります.上の_も使えますソースのフィルタフィールド:
GET weibo/_source/1?_source=user
{
"user" : "niewj"
}
7.インデックス時のstored_fieldsパラメータ
デフォルトでは、フィールド値は検索可能にインデックスされますが、元の値は保存されません.これは、フィールドを調べることができますが、元のフィールド値を取得することはできません.例:
# mapping counter ;tags ;
PUT twitter
{
"mappings": {
"properties": {
"counter": {
"type": "integer",
"store": false
},
"tags": {
"type": "keyword",
"store": true
}
}
}
}
索引レコード:
# , id=1
PUT twitter/_doc/1
{
"counter" : 1,
"tags" : ["red"]
}
クエリ
GET twitter/_doc/1
{
"_index" : "twitter",
"_type" : "_doc",
"_id" : "1",
"_version" : 1,
"_seq_no" : 0,
"_primary_term" : 1,
"found" : true,
"_source" : {
"counter" : 1,
"tags" : [
"red"
]
}
}
すべて調べることができます;stored_の使用fieldsパラメータクエリー:
GET twitter/_doc/1?stored_fields=tags,counter
:{
"_index" : "twitter",
"_type" : "_doc",
"_id" : "1",
"_version" : 1,
"_seq_no" : 0,
"_primary_term" : 1,
"found" : true,
"fields" : {
"tags" : [
"red"
]
}
}
counterフィールドがなくなりました.mappingには
store: false
が設置されているので8.インデックスクエリパフォーマンス関連パラメータの:refresh
refresh
は、getの前に相関スライスをリフレッシュし、検索可能にするためにtrue
に設定される.これをtrueに設定する前に、システムの負荷が重すぎる(インデックス速度が低下する)可能性があるため、よく考慮して確認してください.