1

I have a document with several different attributes. In my app I want to do filtering on one of the doc attributes and possibility sorting by any of the other attribute.

i.e

{
"accountId": "qa32176148",
"id": "122230310111",
"rtSessionId": "qa321761484294973207",
"sessionStartTime": 1387705538426,
"visitorLastUpdateTime": 1387705717094,
"countryCode": "US",
"state": "NY",
"city": "New York",
"country": "United States",
"organization": "Google",
"ipAddress": "216.239.39.99",
"agentNickName": "john"
}

  1. I want to filter by each one of these fields, Should I create a views for each one of the fields ?
  2. (as an example) Can I filer on state and sort by city?
4

1 回答 1

1
  1. 基本上,是的,您需要为每个属性创建单独的视图(以防万一,如果您只想按一个属性过滤)。如果您还需要在一个查询中按两个或多个属性过滤结果,您还需要为每个属性组合提供一个视图。但我不明白你的意思是什么composite index(如果你看到一些例子,如果你展示它会很棒)。据我了解,复合索引根本不适合这种情况。

  2. 是的,在大多数情况下。但是只有当您期望属性完全匹配时,您才能这样做X,即X == 1(不是范围:)X == 1 ... 6。要按属性排序Y,只需将其附加到您的发出函数后,X属性: emit([X,Y], null)并使用startKeyendKey参数。即startKey=[1]endkey=[1,{}]

现在我回到你的第一个问题。我认为这种情况用于某种搜索操作。因此,elasticsearch 有一个很好的 couchbase 扩展另请参阅此页面),这将使您在过滤和排序方面更加灵活,而无需创建很多视图。

于 2013-12-20T22:33:39.423 回答