我需要以 flex 索引“CLIENT”实体。我的对象“CLIENT”人由几个细分(JSON文档)组成,例如

COMMON (firstname, lastname etc),
EDUCATION (fields...),
JOB (fields...) and so on.

所以我的索引必须存储所有这些段(JSON文档)。然后,我必须通过字段和段的不同组合进行搜索,例如:search word "university" in COMMON.firstname, COMMON.lastname, EDUCATION.field1, EDUCATION.field2。并且我可以将所有细分作为客户端列表返回搜索结果

最佳答案

我要说的是,文档可以像这样

{
  ...common properties,
  "education": {
    ...education properties
  },
  "job": {
    ...job properties
  }
}

为了索引这样的文档,您可以执行下一个查询(如果不存在新索引,则会自动创建该索引)
PUT /client/doc/1
{
  "firstName": "...",
  "lastName": "...",
  ...other common properties,
  "education": {
    ...education properties
  },
  "job": {
    ...job properties
  }
}

其中客户是索引名称, doc 是类型, 1 是新文档的ID。

然后,您可以通过执行以下操作获取客户端列表(默认为10个)
GET /client/doc/_search

为了进行搜索,您可以执行(这还将返回最多10个文档,因为默认为10个)
GET /client/doc/_search
{
  "query": {
    "query_string" : {
      "query" : "firstName:university OR lastName:university OR education.field1:university OR education.field1:university",
      "default_field" : "content"
    }
  }
}

如果您想为所有或某些属性明确指定数据类型,请查看dynamic mapping。否则,将根据值分配默认数据类型,例如字符串值的“文本”等。

07-24 09:49
查看更多