NEST Library and query issues

Good day,
I was busy with NEST on elasticsearch, but I have alot of troubling making it work.

I have this code for creating the index

     var typeName = typeof(SEARCHTYPE).Name.ToLower();
     var client = new ElasticClient(Settings);
                client.DeleteIndex(typeName,x=>x.Index(typeName));
                var ax = client.CreateIndex(typeName, c => c
                           .Index(typeName)
                                           .Mappings(m => m.Map<SEARCHTYPE>(d => d.AutoMap())));
            }

and my search is one string with multiple words which should get the best result based on this type. the type has the following fields

title: string
text:string
keywords:string(commaseparated)
identifiers:string(commaseparated)

I want the best result for my search
the priority is as follows:keywords,title identifiers,text

var searches = searchString.Split(' ').Where(x => x.Length > 2);
            var searchItems = new List<string>();
            var synonyms = new List<string>(); //todo
            searchItems.Add(searchString);
            foreach (var searchItem in searches)
            {
                searchItems.Add(searchItem);
                searchItems.AddRange(languageItems.Where(x => x.StartsWith(searchItem)));
            }

            if (!searchItems.Any()) return new ReadOnlyCollection<SearchSuggestion>(new List<SearchSuggestion>());


//Okay, I admit... I need help
            var search=Client.Search<SearchSuggestion>(x => x
                .Query(q => q
                    .Terms(b =>b
                        .Terms(searchItems).Boost(1.6)))                        
                                ); 
            return search.Documents;
        }

Could anybody please help me?
I am having alot of troubles with this...

thank you in advance.

Yureh

You should take a look at the Definitive Guide, particularly:

As a very general approach you could

  1. map keywords and identifiers as a collection of types in your POCO e.g. IEnumerable<string>
  2. analyze these fields at index time in a way that satisfies your problem domain
  3. analyze the query input at search time with a full text query to find matches against indexed documents. The analysis applied at search time does not necessarily need to be the same as that applied at index time.

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