索引付けされたTIMESTAMPスカラーの全文検索

kvstoreという名前のストアを起動し、前述のものと同じtimestamp値を持つtsTableを作成するとします(この値はそれぞれ精度6で表に格納されています)。ストアをElasticsearchクラスタ(eshostという名前のホスト上で実行)に登録すると、管理CLIから次のコマンドを実行することで、表のtsフィールド上にtsIndexという名前のテキスト索引が作成されます。

kv-> execute 'CREATE FULLTEXT INDEX tsIndex ON tsTable (ts{"type":"date"})';

この場合、次のような問合せを実行すると、索引付けされたデータに対して全文検索を実行できます。

昇順でソートされたすべての値のリスト

curl –X GET 'http://eshost:9200/ondb.kvstore.tstable.tsindex/_search?pretty' 
                  '-d {"sort":[{"ts":"asc"}]}'

{
  "took" : 4,
  "timed_out" : false,
  "_shards" : {
    "total" : 3,
    "successful" : 3, 
    "failed" : 0
  },
  "hits" : {
    "total" : 5,
    "max_score" : null,

    "hits" : [ {
      "_index" : "ondb.kvstore.tstable.ts",
      "_type" : "text_index_mapping",
      "_id" : "/w/0000",
      "_score" : null,

      "_source":{"_pkey":{"_table":"tstable","id":"0"},  
                          "ts":"1996-12-31T23:01:43.987654"},

      "sort" : [852073303123]
    
}, {
      "_index" : "ondb.kvstore.tstable.ts",
      "_type" : "text_index_mapping",
      "_id" : "/w/0002",
      "_score" : null,

      "_source":{"_pkey":{"_table":"tstable","id":"2"},  
                          "ts":"1998-10-26T08:33:59.735978"},

      "sort" : [909435821111]
    
}, {
      "_index" : "ondb.kvstore.tstable.ts",
      "_type" : "text_index_mapping",
      "_id" : "/w/0003",
      "_score" : null,

      "_source":{"_pkey":{"_table":"tstable","id":"3"},  
                          "ts":"2001-09-15T23:01:43.555667"},

      "sort" : [995911599555]
  
  }, {
      "_index" : "ondb.kvstore.tstable.ts",
      "_type" : "text_index_mapping",
      "_id" : "/w/0004",
      "_score" : null,

      "_source":{"_pkey":{"_table":"tstable","id":"4"},  
                          "ts":"2002-04-06T17:07:38.765346"},

      "sort" : [1024765658765]
    
}, {
      "_index" : "ondb.kvstore.tstable.ts",
      "_type" : "text_index_mapping",
      "_id" : "/w/0001",
      "_score" : null,

      "_source":{"_pkey":{"_table":"tstable","id":"1"},  
                          "ts":"2005-03-20T14:10:25.258000"},

      "sort" : [1091264176173]
  
  } ]
  }
}

特定の日時を検索する完全一致の実行

curl –X GET 'http://eshost:9200/ondb.kvstore.tstable.tsindex/_search?pretty' 
                  '-d {"query":{"term":{"ts":"2005-03-20T14:10:25.258000"}}}' 

{
  ....
  "hits" : {
    "total" : 1,
    "max_score" : null,

    "hits" : [ {
      "_index" : "ondb.kvstore.tstable.ts",
      "_type" : "text_index_mapping",
      "_id" : "/w/0001",
      "_score" : null,

      "_source":{"_pkey":{"_table":"tstable","id":"1"},  
                          "ts":" 2005-03-20T14:10:25.258000},
  
  } ]
  }
}

特定の日時の範囲内の日付の検索

curl –X GET 'http://eshost:9200/ondb.kvstore.tstable.tsindex/_search?pretty' 
                  '-d {"query":{"range":{"ts":{"gte":" 1998-10-26T08:33:59.735978","lt":" 2002-04-06T17:07:38.9"}}}}' 

{
  ....
  "hits" : {
    "total" : 3,
    "max_score" : null,

    "hits" : [ {
      "_index" : "ondb.kvstore.tstable.ts",
      "_type" : "text_index_mapping",
      "_id" : "/w/0004",
      "_score" : null,

      "_source":{"_pkey":{"_table":"tstable","id":"4"},  
                          "ts":"2002-04-06T17:07:38.765346},
    
}, {
      "_index" : "ondb.kvstore.tstable.ts",
      "_type" : "text_index_mapping",
      "_id" : "/w/0002",
      "_score" : null,

      "_source":{"_pkey":{"_table":"tstable","id":"2"},  
                          "ts":"1998-10-26T08:33:59.735978"},

      "sort" : [909435821111]
    
}, {
      "_index" : "ondb.kvstore.tstable.ts",
      "_type" : "text_index_mapping",
      "_id" : "/w/0003",
      "_score" : null,

      "_source":{"_pkey":{"_table":"tstable","id":"3"},  
                          "ts":"2001-09-15T23:01:43.555667"}
  
  } ]
  }
}