【问题标题】:Alter Table From Cassandra to Elasticsearch SYNC - Elassandra将表从 Cassandra 更改为 Elasticsearch SYNC - Elassandra
【发布时间】:2017-09-27 16:47:31
【问题描述】:

我通过elasticsearch创建了一个表并同步到cassandra:

 _id | message                                    | postDate                            | user
-----+--------------------------------------------+-------------------------------------+------------
   2 |     ['Another tweet, will it be indexed?'] | ['2009-11-15 14:12:12.000000+0000'] | ['kimchy']
   1 | ['Trying out Elassandra, so far so good?'] | ['2009-11-15 13:12:00.000000+0000'] | ['kimchy']

当我更改表格推文并添加电子邮件列时:

ALTER TABLE tweet ADD email varchar;

```

 _id | email | message                                    | postDate                            | user
-----+-------+--------------------------------------------+-------------------------------------+------------
   2 |  null |     ['Another tweet, will it be indexed?'] | ['2009-11-15 14:12:12.000000+0000'] | ['kimchy']
   1 |  null | ['Trying out Elassandra, so far so good?'] | ['2009-11-15 13:12:00.000000+0000'] | ['kimchy']

``` 电子邮件已添加,但显示为 null

但是当我在 elasticsearch 上查询时它不同步:

{
  "took" : 4,
  "timed_out" : false,
  "_shards" : {
    "total" : 1,
    "successful" : 1,
    "failed" : 0
  },
  "hits" : {
    "total" : 2,
    "max_score" : 1.0,
    "hits" : [ {
      "_index" : "twitter",
      "_type" : "tweet",
      "_id" : "2",
      "_score" : 1.0,
      "_source":{"postDate":"2009-11-15T14:12:12.000Z","message":"Another tweet, will it be indexed?","user":"kimchy"}
    }, {
      "_index" : "twitter",
      "_type" : "tweet",
      "_id" : "1",
      "_score" : 1.0,
      "_source":{"postDate":"2009-11-15T13:12:00.000Z","message":"Trying out Elassandra, so far so good?","user":"kimchy"}
    } ]
  }
}

问题是我如何才能将表的更改从 cassandra 同步到 elasticsearch?

【问题讨论】:

  • 你用什么来同步数据..

标签: elasticsearch cassandra


【解决方案1】:

这是一个旧帖子,但我会回答以防有人找到它。

在 Elassandra 中,当您创建 cassandra 表或列时,它不会被 elastisearch 自动索引。您需要创建或更新映射:

curl -XPUT "http://localhost:9200/twitter/" -d '{
   "settings" : { "keyspace" : "twitter" } },
   "mappings" : {
      "tweet" : {
            "properties" : {
              "email" : { "type" : "string", "index" : "not_analyzed" },
            }
      }
   }
}

现在 elasticsearch 索引包含一个新的 email 字段。使用 CQL 插入的任何新电子邮件都会自动编入索引,并可在一秒钟内进行搜索。

但请务必注意,在映射更新之前添加的电子邮件条目尚不可搜索。需要使用nodetool来重建包含旧数据的索引:

nodetool flush tweeter
nodetool rebuild_index --threads 4 tweeter tweet elastic_tweet_idx

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-02-27
    • 2014-07-01
    • 1970-01-01
    • 2017-05-13
    • 2017-09-15
    • 2017-05-12
    相关资源
    最近更新 更多