1

I have a query like below,

Any ideas, why I am getting only the exact match results when I do search . For Example ;

When I search "Aegli" I get results, but when I search for "Aegl" No results returned

query = {
  "query": {
    "query_string": {
      "query": "%s"%q
    }
  },
  "filter": {
    "term": {
      "has_product": 1
    }
  },
  "facets": {
    "destination": {
      "terms": {
        "field": "destination.en"
      },
      "facet_filter": {
        "term": {
          "has_product": 1
        }
      }
    },
    "hotel_class": {
      "terms": {
        "field": "hotel_class"
      },
      "facet_filter": {
        "term": {
          "has_product": 1
        }
      }
    },
    "hotel_type": {
      "terms": {
        "field": "hotel_type"
      },
      "facet_filter": {
        "term": {
          "has_product": 1
        }
      }
    }
  }
}
Saeed Zhiany
  • 2,051
  • 9
  • 30
  • 41
tuna
  • 6,211
  • 11
  • 43
  • 63
  • That's the way an inverted index like lucene is supposed to work. You can either decide to index ngrams (but your index will grow really quickly) or use a wildcard query (slower). – javanna May 29 '13 at 11:34

3 Answers3

1

I do not see your real query but you might be missing * at end of your search word and your query string should be like;

{"query_string": {"query": "%s*"}

For example;

{"query_string": {"query": "Aegl*"}
Ahmet DAL
  • 4,445
  • 9
  • 47
  • 71
  • I think this something that should be solved with NGRAM tokenizers. This method might be bad for scaling. – tuna May 29 '13 at 11:17
  • 1
    You can take a look here for a discussion about tokenizers http://stackoverflow.com/questions/16816628/fetch-all-documents-if-source-contains-the-given-search-text-in-elastic-search-s – jackdbernier May 29 '13 at 19:15
0

Having a mapping like below

{
    "mappings": {
        "hotel": {
            'properties': {"name": {
                "type": "string",
                "search_analyzer": "str_search_analyzer",
                "index_analyzer": "str_index_analyzer"
            }
            }},

    },

    "settings": {
        "analysis": {
            "analyzer": {
                "str_search_analyzer": {
                    "tokenizer": "keyword",
                    "filter": ["lowercase"]
                },

                "str_index_analyzer": {
                    "tokenizer": "keyword",
                    "filter": ["lowercase", "substring"]
                }
            },

            "filter": {
                "substring": {
                    "type": "nGram",
                    "min_gram": 1,
                    "max_gram": 20
                }
            }
        }
    }
}

Solved my problem

tuna
  • 6,211
  • 11
  • 43
  • 63
0

try to add "fuzziness" : "AUTO", in your match, like below eg:

query: {
  bool: {
    must: [
      {
        exists: {
          field: "nid",
        },
      },
      {
        match: {
          status: "true",
        },
      },
      {
        multi_match: {
          query: val,
          type: "best_fields",
          operator: "and",
          fields: ["title"],
          fuzziness: 'AUTO',
        },
      },
    ],
},

This works for me.