Hi,
I am trying to do some aggregations which I will use as filters but I am having a problem with searching the fields I am aggregating. This is my mapping:
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
And this is where I define the query:
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
So far I am able to correctly display my aggregations and search on all fields except on "course_name". The other aggregated field is searchable. The search query sent from RoR to ES looks like this:
{: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=>["course_name"]}}}},
{:multi_match=>{:query=>"salad", :fields=>["name^9", "summary^8", "cuisine_name^7", "description^6"]}}]}},
:aggs=>
{:occasion_aggregation=>
{:nested=>{:path=>"occasions"}, :aggs=>{:id_and_name=>{:terms=>{:script=>"doc['occasions.id'].value + '|' + doc['occasions.occasion_name'].join(' ')", :size=>35}}}},
:course_aggregation=>{:nested=>{:path=>"courses"}, :aggs=>{:id_and_name=>{:terms=>{:script=>"doc['courses.id'].value + '|' + doc['courses.course_name'].join(' ')", :size=>35}}}}}}}
Any help will be much appreciated!