与Couchbase交互说明

Couchbase 与Elasticsearch数据复制系统由下图说明表示:

  1. 红色箭头代表Couchbase SDK与Couchbase集群,进行数据写,查询一般情况通过Document id (也就是唯一KEY)进行交互.

  2. Couchbase数据会实时的同步到Ealsticsearch集群.

  3. Ealsticsearch通过全文检索进行查询,注意返回的是Document id (也就是唯一KEY),而不是完整的数据.

注意:

Couchbase同步到Ealsticsearch中的并非和Couchbase桶中一致的数据.而是包含了当前数据的一些元数据及Document id (也就是唯一KEY)

但是Ealsticsearch的数据一般是保存两份,一份是_source这一份原始数据,另一份是_all,用于全文检索

不明白可以参考:图解Elasticsearch中的_source、_all、store和index属性

当查询的时候

$ curl localhost:9200/travel-sample/_search?q=san+francisco

结果:

{
    "took":5,
    "timed_out":false,
    "_shards":{"total":5,"successful":5,"skipped":0,"failed":0},
    "hits":{
        "total":1599,
        "max_score":11.965878,
        "hits":[
            {"_index":"travel-sample","_type":"couchbaseDocument","_id":"landmark_36047","_score":11.965878,"_source":{"meta":{"rev":"1-1508c18bdbb400000000000002000000","flags":33554432,"expiration":0,"id":"landmark_36047"}}},
            {"_index":"travel-sample","_type":"couchbaseDocument","_id":"landmark_25611","_score":11.905596,"_source":{"meta":{"rev":"1-1508c18bb43400000000000002000000","flags":33554432,"expiration":0,"id":"landmark_25611"}}},
            {"_index":"travel-sample","_type":"couchbaseDocument","_id":"landmark_25712","_score":11.905596,"_source":{"meta":{"rev":"1-1508c18bb61e00000000000002000000","flags":33554432,"expiration":0,"id":"landmark_25712"}}}
            ...
        ]
    }
}

这样在拿匹配到的Document id 根据Couchbase SDK去Couchbase桶中搜索.

应用场景举例

比如说在电子商务搜索场景

  • 产品表是一个桶,产品唯一标示是Document id,比如说产品名称ean,sku等

  • 用户搜索产品,其实一个是一个全文检索的过程(Ealsticsearch)

  • Ealsticsearch拿到检索到的Document id集合,根据Document id拿到产品的详细信息

  • 展示搜索到的产品列表给用户

Last updated

Was this helpful?