[英]Elasticsearch query nested object
我有這個彈性記錄:
{
"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",
}
]
}
我想在聯系信息 object 中查詢,我使用了下面的查詢,但沒有得到任何結果:
{
"query": {
"nested" : {
"path" : "ContactInfo",
"query" : {
"match" : {"ContactInfo.Details" : "Details of tv show"}
}
}
}
}
我也試過:
{
"query": {
"term" : { "ContactInfo.ContactType" : "email" }
}
}
這是聯系信息的映射:
"ContactInfo":{
"type": "object"
}
我想我知道問題是字段未設置為嵌套在映射中,有沒有辦法在不更改映射的情況下仍然嵌套查詢,我只是想盡可能避免重新索引數據。 我對彈性搜索還很陌生,所以需要你的幫助。
提前致謝。
Elasticsearch 沒有內部對象的概念。
Elasticsearch官方文檔關於嵌套字段類型的一些要點
請參閱此SO answer ,以獲取有關此的更多詳細信息
添加具有索引映射、搜索查詢和搜索結果的工作示例
應用嵌套數據類型后,您必須重新索引數據
索引映射:
{
"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"
}
]
}
}
]
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.