elasticsearch Elasticsearch查询嵌套对象
我有这张唱片:elasticsearch Elasticsearch查询嵌套对象,elasticsearch,nested,elasticsearch,Nested,我有这张唱片: { "FirstName": "Winona", "LastName": "Ryder", "Notes": "<p>she is an actress</p>", "Age": "40-50", "Race": "Caucasi
{
"FirstName": "Winona",
"LastName": "Ryder",
"Notes": "<p>she is an actress</p>",
"Age": "40-50",
"Race": "Caucasian",
"Gender": "Female",
"HeightApproximation": "No",
"Armed": false,
"AgeCategory": "Adult",
"ContactInfo": [
{
"ContactPoint": "stranger@gmail.com",
"ContactType": "Email",
"Details": "Details of tv show",
}
]
}
我还尝试:
{
"query": {
"term" : { "ContactInfo.ContactType" : "email" }
}
}
以下是联系人信息的映射:
"ContactInfo":{
"type": "object"
}
我想我知道的问题是,字段在映射中没有设置为嵌套的,有没有一种方法可以在不更改映射的情况下仍然查询嵌套的字段,我只是希望尽可能避免重新索引数据。
我是弹性搜索的新手,需要你的帮助
提前感谢。Elasticsearch没有内部对象的概念。 Elasticsearch官方文档中关于
{
"mappings": {
"properties": {
"ContactInfo": {
"type": "nested"
}
}
}
}
{
"query": {
"nested" : {
"path" : "ContactInfo",
"query" : {
"match" : {"ContactInfo.Details" : "Details of tv show"}
}
}
}
}
"hits": [
{
"_index": "stof_64269180",
"_type": "_doc",
"_id": "1",
"_score": 1.1507283,
"_source": {
"FirstName": "Winona",
"LastName": "Ryder",
"Notes": "<p>she is an actress</p>",
"Age": "40-50",
"Race": "Caucasian",
"Gender": "Female",
"HeightApproximation": "No",
"Armed": false,
"AgeCategory": "Adult",
"ContactInfo": [
{
"ContactPoint": "stranger@gmail.com",
"ContactType": "Email",
"Details": "Details of tv show"
}
]
}
}
]
搜索查询:
{
"mappings": {
"properties": {
"ContactInfo": {
"type": "nested"
}
}
}
}
{
"query": {
"nested" : {
"path" : "ContactInfo",
"query" : {
"match" : {"ContactInfo.Details" : "Details of tv show"}
}
}
}
}
"hits": [
{
"_index": "stof_64269180",
"_type": "_doc",
"_id": "1",
"_score": 1.1507283,
"_source": {
"FirstName": "Winona",
"LastName": "Ryder",
"Notes": "<p>she is an actress</p>",
"Age": "40-50",
"Race": "Caucasian",
"Gender": "Female",
"HeightApproximation": "No",
"Armed": false,
"AgeCategory": "Adult",
"ContactInfo": [
{
"ContactPoint": "stranger@gmail.com",
"ContactType": "Email",
"Details": "Details of tv show"
}
]
}
}
]
搜索结果:
{
"mappings": {
"properties": {
"ContactInfo": {
"type": "nested"
}
}
}
}
{
"query": {
"nested" : {
"path" : "ContactInfo",
"query" : {
"match" : {"ContactInfo.Details" : "Details of tv show"}
}
}
}
}
"hits": [
{
"_index": "stof_64269180",
"_type": "_doc",
"_id": "1",
"_score": 1.1507283,
"_source": {
"FirstName": "Winona",
"LastName": "Ryder",
"Notes": "<p>she is an actress</p>",
"Age": "40-50",
"Race": "Caucasian",
"Gender": "Female",
"HeightApproximation": "No",
"Armed": false,
"AgeCategory": "Adult",
"ContactInfo": [
{
"ContactPoint": "stranger@gmail.com",
"ContactType": "Email",
"Details": "Details of tv show"
}
]
}
}
]
“点击次数”:[
{
“_索引”:“stof_64269180”,
“\u类型”:“\u单据”,
“_id”:“1”,
“_分数”:1.1507283,
“_来源”:{
“名字”:“威诺娜”,
“姓氏”:“赖德”,
“备注”:“她是一名演员”,
“年龄”:“40-50岁”,
“种族”:“白种人”,
“性别”:“女性”,
“高度近似值”:“否”,
“武装”:假,
“年龄类别”:“成人”,
“联系人信息”:[
{
“联系人”:stranger@gmail.com",
“联系人类型”:“电子邮件”,
“详情”:“电视节目详情”
}
]
}
}
]
非常感谢您的全面回复。我很高兴能为您提供帮助