Trouble with Phrase Suggester


(nikhil trivedi) #1

I'm having some trouble implementing the Phrase Suggester using the examples provided in the documentation (https://www.elastic.co/guide/en/elasticsearch/reference/current/search-suggesters-phrase.html).

I've got this mapping:

{
	"...": {
		"aliases": {},
		"mappings": {
			"agent": {
				"properties": {
					"title": {
						"type": "text",
						"fields": {
							"reverse": {
								"type": "text",
								"analyzer": "reverse"
							},
							"trigram": {
								"type": "text",
								"analyzer": "trigram"
							}
						}
					}
				}
			}
		},
		"settings": {
			"index": {
				"number_of_shards": "5",
				"provided_name": "...",
				"creation_date": "...",
				"analysis": {
					"filter": {
						"shingle": {
							"max_shingle_size": "3",
							"min_shingle_size": "2",
							"type": "shingle"
						},
						"english_stemmer": {
							"type": "stemmer",
							"language": "english"
						},
						"english_possessive_stemmer": {
							"type": "stemmer",
							"language": "possessive_english"
						},
						"english_stop": {
							"type": "stop",
							"stopwords": "_english_"
						}
					},
					"analyzer": {
						"reverse": {
							"filter": [
								"standard",
								"reverse"
							],
							"tokenizer": "standard"
						},
						"trigram": {
							"filter": [
								"standard",
								"shingle"
							],
							"tokenizer": "standard"
						},
						"default": {
							"filter": [
								"english_possessive_stemmer",
								"lowercase",
								"english_stop",
								"english_stemmer"
							],
							"tokenizer": "standard"
						}
					}
				},
				"number_of_replicas": "1",
				"uuid": "...",
				"version": {
					"created": "..."
				}
			}
		}
	}
}

With a document with the title "Rauschenberg, Robert", here is the search I'm trying to perform:

{
	"index": "...",
	"type": null,
	"body": {
		"query": {
			"bool": {
				"must": [{
					"multi_match": {
						"query": "Ruschenbrg, robert",
						"fuzziness": 3,
						"prefix_length": 1,
						"fields": ["_all"]
					}
				}],
				"should": [{
					"terms": {
						"id": [...]
					}
				}],
				"filter": null
			}
		},
		"suggest": {
			"text": "Ruschenbrg, robert",
			"phrase-suggest": {
				"phrase": {
					"field": "title.trigram",
					"gram_size": 3,
					"direct_generator": [{
						"field": "title.trigram",
						"suggest_mode": "always"
					}, {
						"field": "title.reverse",
						"suggest_mode": "always",
						"pre_filter": "reverse",
						"post_filter": "reverse"
					}],
					"highlight": {
						"pre_tag": "<em>",
						"post_tag": "<\/em>"
					}
				}
			}
		}
	}
}

And here are the results:

{
	"took": 33,
	"timed_out": false,
	"_shards": {
		"total": 5,
		"successful": 5,
		"failed": 0
	},
	"hits": {
		...
	},
	"suggest": {
		"phrase-suggest": [{
			"text": "Ruschenbrg, robert",
			"offset": 0,
			"length": 18,
			"options": []
		}]
	}
}

You'll see in the suggest block, the options parameter is empty. I would expect it to contain the title of the closely matched document "Rauschenberg, Robert". What am I missing?


(nikhil trivedi) #2

Figured it out. It turned out to be a type name mismatch between the mappings I was creating and the data I was indexing. So new types were being created that didn't include these extra fields and my data was being indexed there.


(Tal Levy) #3

cool, glad to hear this was resolved!


(system) #4

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.