Filtreler olarak kullanacağım bazı toplamaları yapmaya çalışıyorum ama toplu halde olduğum alanları aramakta sorun yaşıyorum. Bu benim haritalama geçerli:Çalışmayan birden çok iç içe geçmiş alanı arama (ES + ROR)
settings :index => { :number_of_shards => 1 } do
mapping do
indexes :id, index: :not_analyzed
indexes :name
indexes :summary
indexes :description
indexes :occasions, type: 'nested' do
indexes :id, type: 'integer'
indexes :occasion_name, type: 'string', index: :not_analyzed
end
indexes :courses, type: 'nested' do
indexes :id, type: 'integer'
indexes :course_name, type: 'string', index: :not_analyzed
end
#
indexes :allergens, type: 'nested' do
indexes :id, type: 'integer'
indexes :allergen_name, type: 'string', index: :not_analyzed
end
#
indexes :cookingtechniques, type: 'nested' do
indexes :id, type: 'integer'
indexes :name, type: 'string', index: :not_analyzed
end
indexes :cuisine, type: 'nested' do
indexes :id, type: 'integer'
indexes :cuisine_name, type: 'string', index: :not_analyzed
end
end
end
Ve sorgu tanımlamak budur:
def multi_match_query(query)
{
bool: {
should: [
{
nested:{
path: 'occasions',
query: {
multi_match:
{
query: query,
type: "best_fields",
fields: ["occasions.occasion_name"]
}
}
}
},
{
nested:{
path:'courses',
query: {
multi_match:
{
query: query,
type: "best_fields",
fields: ["course_name"]
}
}
}
},
{
multi_match: {
query: query,
fields:["name^9", "summary^8", "cuisine_name^7", "description^6"],
}
}
]
}
}
end
Şimdiye kadar düzgün benim Toplamalardan görüntülemek ve "course_name" hariç tüm alanları üzerinde arama yapabiliyor duyuyorum. Diğer toplanmış alan aranabilir (occasion_name). Sorgudaki diğer iç içe geçmiş alanları da eklemek istiyorum ve bunları eklemeyi denedim, ancak yinelenebilir olan yalnızca yuvalanmış alan vekil_adı, diğer tüm yuvalanmış alanlar değil. Bir kaç ES referans kitabını kontrol ettim ama sorgusuz gibi bir şey yok, bu da bana sorguda birden fazla yuvalanmış alan bulunamayacağımı düşünmemi sağlıyor.
DÜZENLEME:
{
"recipes":{
"mappings":{
"recipe":{
"properties":{
"allergens":{
"type":"nested",
"properties":{
"allergen_name":{
"type":"string",
"index":"not_analyzed"
},
"id":{
"type":"integer"
}
}
},
"cookingtechniques":{
"type":"nested",
"properties":{
"id":{
"type":"integer"
},
"name":{
"type":"string",
"index":"not_analyzed"
}
}
},
"courses":{
"type":"nested",
"properties":{
"course_name":{
"type":"string",
"index":"not_analyzed"
},
"id":{
"type":"integer"
}
}
},
"cuisine":{
"type":"nested",
"properties":{
"cuisine_name":{
"type":"string",
"index":"not_analyzed"
},
"id":{
"type":"integer"
}
}
},
"description":{
"type":"string"
},
"id":{
"type":"string",
"index":"not_analyzed"
},
"name":{
"type":"string"
},
"occasions":{
"type":"nested",
"properties":{
"id":{
"type":"integer"
},
"occasion_name":{
"type":"string",
"index":"not_analyzed"
}
}
},
"summary":{
"type":"string"
}
}
}
}
}
}
RoR gelen arama isteğinden sorgusu:
{:query=>
{:bool=>
{:should=>
[{:nested=>{:path=>"occasions", :query=>{:multi_match=>{:query=>"salad", :type=>"best_fields", :fields=>["occasions.occasion_name"]}}}},
{:nested=>{:path=>"courses", :query=>{:multi_match=>{:query=>"salad", :type=>"best_fields", :fields=>["courses.course_name"]}}}},
{:multi_match=>{:query=>"salad", :fields=>["name^9", "summary^8", "cuisine_name^7", "description^6"]}}]}}
Herhangi bir yardım çok takdir edilecektir İşte benim haritalama json olduğunu!
Hala çözülmedi mi? Haritalandırmanızı paylaşabilir misiniz? Elbette derslerin yuvalanmış bir alan olmadığını biliyorum. curl -XGET 'http: // localhost: 9200//_mapping/' –
Rahul
Gönderiyi json ile güncelledim. Yardımınız için tekrar teşekkürler, gerçekten takdir ediyorum! – martini
Teşekkürler. haritalama gayet iyi. Alanın mutlak yolu ile denedin mi? "course_name" yerine "courses.course_name"? – Rahul