2016-07-26 4 views
0

indexdocに作成しました。 docのマッピングを追加します。elasticsearchはマッピングで有効になっていないとフィールドにttlを返しません

curl http://localhost:9200/test -X POST 
{"acknowledged":true} 

curl http://localhost:9200/test/student_doc/_mappings -X PUT -d '{ 
    "student_doc" : { 
    "properties" : { 
     "name" : { 
     "properties" : { 
      "student_id" : { 
      "type" : "string" 
      }, 
      "tags": { 
      "type" : "string" 
      } 
     } 
     } 
    } 
    } 
}' 
{"acknowledged":true} 

私はドキュメントを作成するときに、私はdocに関するttlを与えました。

curl http://localhost:9200/test/student_doc/4?ttl=2500 -X PUT -d '{"student_id": "4", "tags": ["test"]}' -H 'Content-type: application/json' 
{"_index":"test","_type":"student_doc","_id":"4","_version":1,"created":true}' 

私は新しいマッピングを使用してインデックスにttlを有効fields

curl http://localhost:9200/test/_search?pretty -X POST -d '{"fields": ["_ttl"]}' 
{ 
    "took" : 1, 
    "timed_out" : false, 
    "_shards" : { 
    "total" : 5, 
    "successful" : 5, 
    "failed" : 0 
    }, 
    "hits" : { 
    "total" : 1, 
    "max_score" : 1.0, 
    "hits" : [ { 
     "_index" : "test", 
     "_type" : "student_doc", 
     "_id" : "4", 
     "_score" : 1.0 
    } ] 
    } 
} 

ttlを取得しよう。

curl http://localhost:9200/test/student_doc/_mappings -X PUT -d '{ 
    "student_doc" : { 
    "_ttl": {"enabled": true}, 
    "properties" : { 
     "name" : { 
     "properties" : { 
      "student_id" : { 
      "type" : "string" 
      }, 
      "tags": { 
      "type" : "string" 
      } 
     } 
     } 
    } 
    } 
}' 

次に新しいレコードを追加します。

curl "http://localhost:9200/test/student_doc/5?ttl=2500&pretty" -X PUT -d '{"student_id": "5", "tags": ["test"]}' -H 'Content-type: application/json' 
{ 
    "_index" : "test", 
    "_type" : "student_doc", 
    "_id" : "5", 
    "_version" : 1, 
    "created" : true 
} 

そして再びttlを取得しようと、それはフィールドでttlを返します。

curl http://localhost:9200/test/_search?pretty -X POST -d '{"fields": ["_ttl"]}' 
{ 
    "took" : 1, 
    "timed_out" : false, 
    "_shards" : { 
    "total" : 5, 
    "successful" : 5, 
    "failed" : 0 
    }, 
    "hits" : { 
    "total" : 2, 
    "max_score" : 1.0, 
    "hits" : [ { 
     "_index" : "test", 
     "_type" : "student_doc", 
     "_id" : "4", 
     "_score" : 1.0 
    }, { 
     "_index" : "test", 
     "_type" : "student_doc", 
     "_id" : "5", 
     "_score" : 1.0, 
     "fields" : { 
     "_ttl" : -420 
     } 
    } ] 
    } 
} 

それは文書で行わ取得するマッピングでttlを有効にするために義務付けられていますか?

+0

はい、 '_ttl'はデフォルトでは有効になっていないため、TTLを有効にするためには有効にする必要がありますが、既に作成されたドキュメントには影響しません。 – Val

+0

@Val 'ttl'を設定できない場合は' PUT'呼び出しでエラーが発生しますか?なぜなら、私は '創造された:真実 'を得て、私はそれがすべての価値観を取っていると考えているからです。 – Nilesh

+0

'_ttl'が有効になっていないと、' ttl'パラメータは暗黙的に無視されます。そのため、あなたは何のエラーも受け取りません。あなたのマッピングを知ること、そしてTTLを有効にしたのかどうかはあなたの仕事の一部です。 – Val

答えて

1

はい、_ttlはデフォルトでは有効になっていないため、TTLを有効にするために有効にする必要がありますが、作成済みのドキュメントには影響しません。

ttlパラメータは、_ttlがマッピングで有効になっていない場合、暗黙のうちに無視されます。そのため、エラーは発生しません。あなたのマッピングを知ること、そしてTTLを有効にしたのかどうかはあなたの仕事の一部です。

いつでも_ttlを有効にすることができます。サポートを増やす作業があれば、必要なときにのみ有効にする必要があります。

関連する問題