i'm trying to find all the keywords in an index. This is for doing an auto complete on a word while typing.
but how would you set up that filter? or do I need to map this with the index?
note: I don't want to autocomplete on a file full result name (so If I store that big brown fox is dead
) the results could be big
, brown
, fox
and dead
)
and the more of for example I have the word fox
being indexed, the higher it's score is
I have a full autocomplete on the whole word while you type (so this isn't what i'm looking for):
This would give me that big brown fox is dead
when I type fo
. instead of only fox
var c = new ElasticClient();
var results = c.Search<dm_document>(s => s
.From(from)
.Size(size)
.Index("testindex")
.Query(q => q.Term(d => d.object_name.Suffix("autocomplete"), search))
);
return results.Documents.Select(d => new { d.object_name, d.r_object_id }).ToList();
with the following index setup
var createResult = client.CreateIndex("testindex", index => index
.Analysis(analysis => analysis
.Analyzers(a => a
.Add(
"autocomplete",
new Nest.CustomAnalyzer() {
Tokenizer = "edgeNGram",
Filter = new string[] { "lowercase" }
}
)
)
.Tokenizers(t => t
.Add(
"edgeNGram",
new Nest.EdgeNGramTokenizer() {
MinGram = 1,
MaxGram = 20
}
)
)
)
.AddMapping<dm_document>(tmd => tmd
.Properties(props => props
.MultiField(p => p
.Name(t => t.object_name)
.Fields(tf => tf
.String(s => s
.Name(t => t.object_name)
.Index(Nest.FieldIndexOption.NotAnalyzed)
)
.String(s => s
.Name(t => t.object_name.Suffix("autocomplete"))
.Index(Nest.FieldIndexOption.Analyzed)
.IndexAnalyzer("autocomplete")
)
.String(s => s
.Name(t => t.title)
.Index(Nest.FieldIndexOption.NotAnalyzed)
)
.String(s => s
.Name(t => t.title.Suffix("autocomplete"))
.Index(Nest.FieldIndexOption.Analyzed)
.IndexAnalyzer("autocomplete")
)
.String(s => s
.Name(t => t.text)
.Index(Nest.FieldIndexOption.Analyzed)
.IndexAnalyzer("snowball")
)
.String(s => s
.IndexName("tag")
.Name("keywords_test")
.IndexAnalyzer("keywords")
)
)
)
)
)
);
but this results in the full name of the objects, I want only the keywords
Update: Found out how to get the terms, not sure if this result is what I need, but it's giving me already terms
POST _search
{
"query" : { "query_string" : {"query" : "*"} },
"facets": {
"tags": {
"terms": {
"field": "title"
}
}
}
}
Now I need to figure out on how to search on those terms