[英]Create index in elasticsearch with different document types
我需要在弹性中索引“客户”实体。 我的 object “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
}
}
其中client是索引名称, 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"
}
}
}
如果您想为所有或部分属性明确指定数据类型,请查看动态映射。 否则,将根据值分配默认数据类型,例如字符串值的“文本”等。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.