# NEST Library and query issues

**URL:** <https://discuss.elastic.co/t/nest-library-and-query-issues/79934>\
**Category:** Elasticsearch\
**Created:** [March 24, 2017, 6:19pm UTC](https://discuss.elastic.co/t/nest-library-and-query-issues/79934 "2017-03-24T18:19:08Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![yurehspellflinger](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/yurehspellflinger/32/16709_2.png) [@yurehspellflinger](https://discuss.elastic.co/u/yurehspellflinger)\
**Post date:** [March 24, 2017, 6:19pm UTC](https://discuss.elastic.co/t/nest-library-and-query-issues/79934/1 "2017-03-24T18:19:08Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![forloop](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/forloop/32/9021_2.png) [@forloop](https://discuss.elastic.co/u/forloop)\
**Post date:** [March 29, 2017, 6:32am UTC](https://discuss.elastic.co/t/nest-library-and-query-issues/79934/2 "2017-03-29T06:32:01Z")

</div>

You should take a look at the [Definitive Guide](https://www.elastic.co/guide/en/elasticsearch/guide/current/index.html), particularly:

- [Mapping and Analysis](https://www.elastic.co/guide/en/elasticsearch/guide/current/mapping-analysis.html)
- [Search in Depth](https://www.elastic.co/guide/en/elasticsearch/guide/current/search-in-depth.html)
- [Dealing with Human Language](https://www.elastic.co/guide/en/elasticsearch/guide/current/languages.html)

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](https://www.elastic.co/guide/en/elasticsearch/reference/current/full-text-queries.html) 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_.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [April 26, 2017, 6:32am UTC](https://discuss.elastic.co/t/nest-library-and-query-issues/79934/3 "2017-04-26T06:32:14Z")

</div>

Closed on April 26, 2017, 6:32am UTC

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