0
votes

I'm getting 0 results doing the following on a new index

GET /umd/_search
{
  "query":{
      "prefix": {
        "title":  "Family Guy"
      }
  }
}

However doing this returns the right result

GET /umd/_search
{
  "query": {
    "match_phrase": {
      "title": {
        "query": "Family Guy",
        "slop": 1
      }
    }
  }
}

How can I get prefix search to work? Ideally I'd like it to return the record if I search for "Family G"

Do I have to set the title type to "not analyzed" for prefix search to work? E.g.

"type": "string",
"index": "not_analyzed"

How can I get match_phrase search working with the query search term "Family Gu"?

1

1 Answers

1
votes

Do I have to set the title type to "not analyzed" for prefix search to work?

Yes, you do. It is also mentioned here: http://www.elasticsearch.org/guide/en/elasticsearch/guide/current/prefix-query.html

That being said, I would not recommend this method. It's really meant for quick demos/spikes. For a more efficient and scalable solution, I would recommend utilizing edge n-grams.

http://www.elasticsearch.org/guide/en/elasticsearch/guide/current/_index_time_search_as_you_type.html