简体   繁体   English

在 elasticsearch 中使用不同的文档类型创建索引

[英]Create index in elasticsearch with different document types

I need to index "CLIENT" entity in elastic.我需要在弹性中索引“客户”实体。 My object "CLIENT" person consist of few segments (JSON documents) like我的 object “CLIENT” 人由几个片段(JSON 文档)组成,例如

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

So my index have to store all this segments(JSON documents).所以我的索引必须存储所有这些段(JSON 文档)。 Then i have to search for by different combination of fields and segments like: search word "university" in COMMON.firstname, COMMON.lastname, EDUCATION.field1, EDUCATION.field2 .然后我必须通过字段和段的不同组合进行搜索,例如: search word "university" in COMMON.firstname, COMMON.lastname, EDUCATION.field1, EDUCATION.field2 AND could i return search results as List of CLIENT with all segments并且我可以将搜索结果作为包含所有细分的客户列表返回吗

I would say, that a document can look like this我会说,文件可能看起来像这样

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

In order to index such document you can execute next query ( a new index, if does not already exist, will be created automatically )为了索引这样的文档,您可以执行下一个查询(新索引,如果不存在,将自动创建)

PUT /client/doc/1
{
  "firstName": "...",
  "lastName": "...",
  ...other common properties,
  "education": {
    ...education properties
  },
  "job": {
    ...job properties
  }
}

Where client is the index name, doc is the type and 1 is the id of the new document.其中client是索引名称, doc是类型, 1是新文档的id。

And then you can get a list of clients (10 by default) by executing然后您可以通过执行获取客户端列表(默认为 10)

GET /client/doc/_search

In order to search you can execute (this will also return max 10 docs as 10 is the default)为了搜索,您可以执行(这也将返回最多 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"
    }
  }
}

If you would like to explicitly specify data types for all or some of the properties please take a look at dynamic mapping .如果您想为所有或部分属性明确指定数据类型,请查看动态映射 Otherwise the default data types will be assigned based on the values, like "text" for string values and etc.否则,将根据值分配默认数据类型,例如字符串值的“文本”等。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM