happy
happy

Reputation: 2628

Proximity-Relevance in elasticsearch

I have an json record in the elastic search with fields

"streetName": "5 Street",
 "name": ["Shivam Apartments"]

I tried the below query but it does not return anything if I add streetName bool in the query

{
    "query": {
        "bool": {
            "must": [
                {
                    "bool": {
                        "must": {
                            "match": {
                                "name": {
                                    "query": "shivam apartments",
                                    "minimum_should_match": "80%"
                                }
                            }
                        }
                    }
                },
                {
                    "bool": {
                        "must": {
                            "match": {
                                "streetName": {
                                    "query": "5 street",
                                    "minimum_should_match": "80%"
                                }
                            }
                        }
                    }
                }
            ]
        }
    }
}

Document Mapping

{
    "rabc_documents": {
        "mappings": {
            "properties": {
                "name": {
                    "type": "text",
                    "analyzer": "autocomplete_analyzer",
                    "position_increment_gap": 0
                },
                "streetName": {
                    "type": "keyword"
                }
            }
        }
    }
}

Upvotes: 0

Views: 134

Answers (1)

Sahil Gupta
Sahil Gupta

Reputation: 2166

Based on the E.S Documentation (Keywords in Elastic Search)

  • "Keyword fields are only searchable by their exact value".
  • Along with that keywords are case sensitive as well.

Taking aforementioned into account:

  1. Searching for "5 street" will not match "5 Street" ('s' vs 'S') on keyword field
  2. minimum_should_match will not work on a keyword field.

Suggestion: For partial matches use "text" mapping instead of "keyword". Keywords are meant to be used for filtering, aggregation based on term, etc.

Upvotes: 1

Related Questions