I am using elasticsearch on the yii2 framework using the elasticsearch extension.
I have to index some location data in elasticsearch as follows:
- id
- countryName
- stateName
- cityName
- addressName
I sould be able to find a location based on provided data such as:
- where countryName='united states' and stateName='new york'
- where cityName='broadway'
- where countryName='united states' and stateName like '%york'
and it should be case insensitive.
Currently when I am doing a query, I don't get any results if the case does not match.
My mappings are:
properties :
id :
type : long
countryName
type : string
fields :
raw :
type : string
index : not_analyzed
stateName
type : string
fields :
raw :
type : string
index : not_analyzed
cityName
type : string
fields :
raw :
type : string
index : not_analyzed
addressName
type : string
fields :
raw :
type : string
index : not_analyzed
And i added an analyzer:
analysis :
analyzer :
analyzer_keyword :
tokenizer : keyword
filter : lowercase
When I do a query countryName='United States'
, I don't get anything, but if I do countryName='united states'
, I get the records that match
When I do countryName.raw='United States'
, I get records that match, but if it's lowercase I don't get anything.
For stateName
, cityName
and addressName
, if I make a query like:
stateName='New York'
or change it to lowercase I do not get any results.
If I do for stateName.raw
, cityName.raw
and addressName.raw
, it works like the countryName.raw
Can anyone help me with this?