我有弹性的记录:
{
"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": {
"nested" : {
"path" : "ContactInfo",
"query" : {
"match" : {"ContactInfo.Details" : "Details of tv show"}
}
}
}
}
我也尝试过:
{
"query": {
"term" : { "ContactInfo.ContactType" : "email" }
}
}
这是联系信息的映射:
"ContactInfo":{
"type": "object"
}
我想我知道问题是字段未设置为映射中的嵌套,有没有一种方法可以在不更改映射的情况下仍然查询嵌套,我只是想避免在可能的情况下重新索引数据。 我对弹性搜索还很陌生,因此需要您的帮助。
谢谢。
答案 0 :(得分:1)
Elasticsearch没有内部对象的概念。
Elasticsearch官方文档中关于Nested field type
的一些要点请参阅此SO answer,以获取有关此内容的更多信息
添加带有索引映射,搜索查询和搜索结果的工作示例
您必须在应用嵌套数据类型之后重新索引数据
索引映射:
self._training = False
搜索查询:
{
"mappings": {
"properties": {
"ContactInfo": {
"type": "nested"
}
}
}
}
搜索结果:
{
"query": {
"nested" : {
"path" : "ContactInfo",
"query" : {
"match" : {"ContactInfo.Details" : "Details of tv show"}
}
}
}
}