1

我的 CouchDB 数据库的结构如下:

"custom_details": {
  "user_education": [
    {
      "device_id": "358328030246627",
      "college_name": "College",
      "college_year": "2014"
    },
  ]
}

"custom_details_1": {
  "user_education": [
    {
      "device_id": "358328030246627",
      "college_name": "College",
      "college_year": "2014"
    },
  ]
}

我在数组中有很多数组。我正在尝试使用 Elasticsearch 搜索和查找术语,无论它位于数组中的哪个位置。那可能吗?

我一直在浏览这里的示例,但还没有找到我想要的东西。我尝试过使用Elastica,PHP Wrapper,但在没有完全理解如何使用 REST 做到这一点的情况下,我迷路了。甚至可以在不知道字段的情况下搜索数据吗?

4

2 回答 2

0

在 Lucene 中,您可以为每个设备 ID 创建一个文档实例:

public void indexRecord(CouchDBRecord rec) {
    Document doc = new Document();
    doc.add(new Field("device_id", rec.device_id, Store.YES, Index.NOT_ANALYZED));
    doc.add(new Field("college_name",  rec.college_name, Store.YES, Index.ANALYZED));
    doc.add(new Field("college_year", rec.college_year.toString(), Store.YES, Index.NOT_ANALYZED));
    this.writer.addDocument(doc);
}

这将允许您按大学名称中的关键字、确切的设备 ID 或年份或它们的某种组合进行搜索。

于 2011-05-22T04:10:27.937 回答
0

如果您使用的是 Elastica,那么整个 REST 事情已经为您完成了。如果要在所有字段中搜索,您可以只定义搜索词,它将在所有字段中搜索。

如果您在使用 Elastica 时遇到问题,或者缺少某些您需要的功能,请告诉我,因为我是 Elastica 的开发人员。

于 2011-06-18T09:15:26.877 回答