I am building Rails web app with elasticsearch-model gem. I would like to build search query with filtering for my Place model. I succeded in wrtiting search by name however I would like to be able to filter my search with city(In this example London).
For now my query looks like this:
"query": {
"bool": {
"must": {
"match": {
"name": {
"query": term,
"operator": "and",
"fuzziness": 1
}
}
},
"filter": {
"term": {
"city": "London"
}
}
}
}
and than I simple invoke Place.search("here goes query").records.to_a
without filter part search works fine, but when I add filter I don't get any result.
This is mapping for Place search:
settings analysis: {
filter: {
ngram_filter: {
type: "nGram",
min_gram: 2,
max_gram: 20
}
},
analyzer: {
ngram_analyzer: {
type: "custom",
tokenizer: "standard",
filter: [
"lowercase",
"asciifolding",
"ngram_filter"
]
},
whitespace_analyzer: {
type: "custom",
tokenizer: "whitespace",
filter: [
"lowercase",
"asciifolding"
]
}
}
} do
mappings dynamic: 'false' do
indexes :name,
type: "string",
analyzer: "ngram_analyzer",
search_analyzer: "whitespace_analyzer"
Here is the link I was using to see how to filter: Elasticsearch doc