0

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?

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
user2707590
  • 1,066
  • 1
  • 14
  • 28
  • How does that `analyzer_keyword` get used? I don't see it in the mappings. Also, what does your query look like? Is it a terms query? Sorry, I am not familiar with the yii framework which might be abstracting the details of the query. But my guess is that if you actually specify your criteria like you do in the post, then it's probably using a terms query and the text is unanalyzed and there will be no results. The `match` query is more appropriate for text searches like this unless you are dealing with numbers, enums, etc. – eemp Jun 13 '16 at 13:56
  • Check out this two links that might be helpful to resolve your issue. http://stackoverflow.com/questions/9421358/filename-search-with-elasticsearch/9432450#9432450 Or else http://jontai.me/blog/2013/02/adding-autocomplete-to-an-elasticsearch-search-application/ – vijay nathji Jun 15 '16 at 05:53

0 Answers0