0

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

Kiwi
  • 2,713
  • 7
  • 44
  • 82
  • I'd start reading [this](https://www.elastic.co/guide/en/elasticsearch/guide/current/_index_time_search_as_you_type.html) and [this](https://www.elastic.co/guide/en/elasticsearch/guide/current/_query_time_search_as_you_type.html) and then come up with a better SO post. – Andrei Stefan Jul 22 '15 at 11:18
  • @AndreiStefan The problem with anything I find (including those 2 links) the results are always the full name, not just the keywords. – Kiwi Jul 22 '15 at 11:25
  • I don't know what you mean. And you really need to update your post: you have nothing about your attempts at solving this and your question is not clear at all. At this pace, your post will be closed because simply is not clear what you ask. – Andrei Stefan Jul 22 '15 at 11:27
  • @AndreiStefan was updating as you posted that. see now – Kiwi Jul 22 '15 at 11:30

0 Answers0