Search-as-you-type with bool query and suggestions

Hi! I'm new in elasticsearch and I want to try a search-as-you-type application with bool query and suggestions. I use Ruby on Rails. Here my mapping:

  settings do
    mappings dynamic: 'false' do
      indexes :locale, type: :keyword
      indexes :search, type: :completion
      indexes :configuration, type: :nested do
        indexes :data, dynamic: 'true' do
        end
      end
    end
  end

Here my search query:

{
query: {
    bool: {
        must: [
        {
            constant_score: {
                filter: {
                    term: {
                        locale: 'en'
                    }
                }
            }
        }, {
            nested: {
                path: 'configuration',
                query: {
                    constant_score: {
                        filter: {
                            terms: {
                                'configuration.data.first': ['s']
                            }
                        }
                    }
                }
            }
        }, {
            nested: {
                path: 'configuration',
                query: {
                    constant_score: {
                        filter: {
                            terms: {
                                'configuration.data.second': ['p']
                            }
                        }
                    }
                }
            }
        }
        ]
    }
},
suggest: {
    suggestions: {
        text: 'hello t',
        completion: {
            field: 'search'
        }
    }
}

Is it possible to use suggest and query at the same time? I want to get suggests on the subset queried by locale and configuration. Is this the right way to accomplish what I want to do or not? I know about context suggester but I don't know how to access nested fields.

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.