Вопрос

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?

Это было полезно?

Решение

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.

Другие советы

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.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top