使用 Elastic Search 查询 CouchDB 中的数组内部

发布于 2024-11-08 12:44:13 字数 678 浏览 4 评论 0原文

我的 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 包装器),但由于没有完全理解如何使用 REST 来实现这一点,所以我迷失了方向。是否可以在不了解领域的情况下搜索数据?

My CouchDB database is structured like this:

"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"
    },
  ]
}

I have a lot of arrays within arrays. What I'm trying to do use Elasticsearch to search and find terms, regardless of where it's sitting in an array. Is that possible?

I've been going through the examples on here and haven't quite found what I'm looking for. I've tried using Elastica, the PHP Wrapper, but without fully understanding how to do this with REST, I'm lost. Is it even possible to search for data without knowing the field?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

第七度阳光i 2024-11-15 12:44:13

在 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 或年份、或者它们的某种组合进行搜索。

In Lucene, you could create a document instance for each device 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);
}

This will allow you to search by keywords in the college name, or by exact device id or year, or some combination thereof.

别忘他 2024-11-15 12:44:13

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

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

If you are using Elastica, the whole REST thing is already done for you. If you want to search in all fields, you can define just the search term and it will search in all fields.

If you are having some troubles with Elastica or if some features are missing you need, let me know, as I'm the developer of Elastica.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文