# Using NEST - No Results

**URL:** <https://discuss.elastic.co/t/using-nest-no-results/106191>\
**Category:** Elasticsearch\
**Created:** [November 2, 2017, 12:18pm UTC](https://discuss.elastic.co/t/using-nest-no-results/106191 "2017-11-02T12:18:52Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![parsa](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/parsa/32/23227_2.png) [@parsa](https://discuss.elastic.co/u/parsa)\
**Post date:** [November 2, 2017, 12:18pm UTC](https://discuss.elastic.co/t/using-nest-no-results/106191/1 "2017-11-02T12:18:52Z")

</div>

This is my result of search by calling:  
[http://localhost:9200/servers/server/\_search?q=servername:"server1-9"](http://localhost:9200/servers/server/_search?q=servername:%22server1-9%22)

`{"took":1233,"timed_out":false,"_shards":{"total":5,"successful":5,"skipped":0,"failed":0},"hits":{"total":1,"max_score":1.3121848,"hits":[{"_index":"servers","_type":"server","_id":"Server1-9","_score":1.3121848,"_source":{"upload":false,"processcount":0,"ip":"127.0.0.1","description":"HP Blade1 Bay9","subtitlefolderpath":null,"ipvalid":"127.0.0.1","type":null,"processsize":0,"switch_device":"Cisco3550","@timestamp":"2017-10-22T18:47:31.680Z","port_number":"GI-1-1","servername":"Server1-9","dnsname":"127.0.0.1","ftpusername":null,"@version":"1","action":"Convert","location":"teh","id":30,"webservice":"http://127.0.0.1/webservice.asmx/CpuAndHDD","ftppassword":null}}]}}`

How Can I implement this serarch with nest? I used this :

```
public class Servers
{
public string ServerName { get; set; }
public string Action { get; set; }
public bool Upload { get; set; }
}

     var responses = client.Search<Servers>(s => s.Index("servers").Type("server").Query(q => q.Term(t => 
     t.ServerName.ToLower(), "server1-9")));
     var response = client.Search<Servers>(s => s.AllTypes().AllIndices().MatchAll());
     var result = response.Documents.ToList();
     foreach (var server in result)
     {
        Response.Write("ServerName : " + server.ServerName + " Action : " + server.Action + "Upload : " + 
       server.Upload + "<br/>");
     }

```

But no results returned.

---

<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:** [November 2, 2017, 11:25pm UTC](https://discuss.elastic.co/t/using-nest-no-results/106191/2 "2017-11-02T23:25:23Z")

</div>

In your example, you're executing a `query_string` query so the equivalent in NEST is

```auto
var response = client.Search<Servers>(s => s
    .Index("servers")
    .Type("server")
    .Query(q => q
        .QueryString(qs => qs
            .Query("servername:\"server1-9\"")
        )
    )
);

```

If searches for `Server` types should always use `"servers"` index and `"server"` type, then you can specify these as defaults to use for `Server` on `ConnectionSettings`

```auto
var pool = new SingleNodeConnectionPool(new Uri("http://localhost:9200"));
var connectionSettings = new ConnectionSettings(pool)
    .InferMappingFor<Servers>(m => m
        .IndexName("servers")
        .TypeName("server")
    );

var client = new ElasticClient(connectionSettings);

```

Then you can simply do

```auto
var response = client.Search<Servers>(s => s
    .Query(q => q
        .QueryString(qs => qs
            .Query("servername:\"server1-9\"")
        )
    )
);

```

---

<div class="post-metadata">

**Author:** ![parsa](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/parsa/32/23227_2.png) [@parsa](https://discuss.elastic.co/u/parsa)\
**Post date:** [November 5, 2017, 3:57pm UTC](https://discuss.elastic.co/t/using-nest-no-results/106191/3 "2017-11-05T15:57:16Z")

</div>

Thank you so much. How can I have "server" word in results ,searching "server" word no returns result.  
And for sorting results what can I do?

---

<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:** [November 5, 2017, 10:19pm UTC](https://discuss.elastic.co/t/using-nest-no-results/106191/4 "2017-11-05T22:19:24Z")

</div>

> [@parsa](#):
>
> How can I have "server" word in results ,searching "server" word no returns result.

Take a look at [analysis and analyzers](https://www.elastic.co/guide/en/elasticsearch/reference/current/analysis.html), and the [NEST section on writing analyzers](https://www.elastic.co/guide/en/elasticsearch/client/net-api/current/analysis.html).

Configuring analyzers to fit the search problem of your domain is an iterative approach you can take to improve the search experience.

> [@parsa](#):
>
> And for sorting results what can I do?

Take a look at [sorting](https://www.elastic.co/guide/en/elasticsearch/reference/current/search-request-sort.html) and the [Sort Usage documentation for NEST](https://www.elastic.co/guide/en/elasticsearch/client/net-api/current/sort-usage.html).

---

<div class="post-metadata">

**Author:** ![parsa](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/parsa/32/23227_2.png) [@parsa](https://discuss.elastic.co/u/parsa)\
**Post date:** [November 6, 2017, 4:10pm UTC](https://discuss.elastic.co/t/using-nest-no-results/106191/5 "2017-11-06T16:10:02Z")

</div>

Thank you

---

<div class="post-metadata">

**Author:** ![parsa](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/parsa/32/23227_2.png) [@parsa](https://discuss.elastic.co/u/parsa)\
**Post date:** [November 10, 2017, 11:19am UTC](https://discuss.elastic.co/t/using-nest-no-results/106191/6 "2017-11-10T11:19:16Z")

</div>

I want to implement suggest and search wtih recommended structure at top that it returns the index word in search results,have sort option and autocomplete option.  
But I don't know how can I implement this query.  
The documents are confusing for me.  
For search I perform as this below:

```
   string word="hello";
        var response = client.Search<Servers>(s => s
        .Query(q => q
        .QueryString(qs => qs
        .Query("servername:\"" + Word + "\"" + "+OR+"+ "action:\""+ Word +"\"").Analyzer("videos")
                )
            ).Sort(st=>st.Descending(vs.Gorean_Date))
        );

```

it has no any results, and I know somthings in my work is wrong.  
And for suggest, I don't know how can implment that.

---

<div class="post-metadata">

**Author:** ![parsa](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/parsa/32/23227_2.png) [@parsa](https://discuss.elastic.co/u/parsa)\
**Post date:** [November 11, 2017, 10:26am UTC](https://discuss.elastic.co/t/using-nest-no-results/106191/7 "2017-11-11T10:26:50Z")

</div>

Anyone can help me?

---

<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:** [November 13, 2017, 12:45am UTC](https://discuss.elastic.co/t/using-nest-no-results/106191/8 "2017-11-13T00:45:17Z")

</div>

> [@parsa](#):
>
> it has no any results, and I know somthings in my work is wrong.

It's very difficult to know what is wrong in your particular case, but I would recommend [using string interpolation](https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/interpolated-strings) for the `query_string` query. I think it'll make your query easier to read and reason about i.e.

```auto
"servername:\"" + Word + "\"" + "+OR+"+ "action:\""+ Word +"\""

```

becomes

```auto
$"servername:\"{Word}\" OR action:\"{Word}\""

```

I don't think you need the `+` around `OR`.

> [@parsa](#):
>
> And for suggest, I don't know how can implment that.

Take a look at the [Suggesters documentation](https://www.elastic.co/guide/en/elasticsearch/reference/5.6/search-suggesters.html), then at the [Suggest usage in NEST](https://www.elastic.co/guide/en/elasticsearch/client/net-api/current/suggest-usage.html). The NEST documentation provides examples of using term, completion and phrase suggesters in one API call, with both fluent lambda syntax and object initializer syntax examples.

---

<div class="post-metadata">

**Author:** ![parsa](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/parsa/32/23227_2.png) [@parsa](https://discuss.elastic.co/u/parsa)\
**Post date:** [November 13, 2017, 6:01pm UTC](https://discuss.elastic.co/t/using-nest-no-results/106191/9 "2017-11-13T18:01:18Z")

</div>

Can you give me an simple example base on my search for suggestion option.

---

<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:** [November 14, 2017, 11:17pm UTC](https://discuss.elastic.co/t/using-nest-no-results/106191/10 "2017-11-14T23:17:34Z")

</div>

It's not clear how you would like suggesters to work in your case. The simplest approach to start with is to:

1. Map a field with the `completion` datatype

2. Index a document with completion inputs

3. Search using the [completion suggester](https://www.elastic.co/guide/en/elasticsearch/reference/5.6/search-suggesters-completion.html)

---

<div class="post-metadata">

**Author:** ![parsa](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/parsa/32/23227_2.png) [@parsa](https://discuss.elastic.co/u/parsa)\
**Post date:** [November 16, 2017, 11:31am UTC](https://discuss.elastic.co/t/using-nest-no-results/106191/11 "2017-11-16T11:31:19Z")

</div>

I implement this below for searching on my two columns of table:  
Fields : "Subject" , "Description"  
TableName : "Video"

```
   string word="Hello World";
    public class Video
    {
        public CompletionField Subject { get; set; }
        public CompletionField Description { get; set; }
    }
    var createIndexResponse = client.CreateIndex("my_video", c => c
   .Mappings(m => m
    .Map<Video>(u => u
        .AutoMap()
    )
)

```

);

for indexing document :

```
         var question = new Video
         {
             Subject = new CompletionField
             {
                 Input = new[] { Word },
                 Weight = 5
             },
            Description = new CompletionField
            {
                Input = new[] { Word },
                Weight = 5
            }
         };
         client.Index(question, i => i.Index("my_video").Refresh(Refresh.WaitFor));

```

and search with using completion suggester :

```
        var response = client.Search<Video>(s => s
        .Index("my_video")
        .Suggest(su => su
            .Completion("suggested_titles", cs => cs
                .Field(f => f.Subject).Field(x=>x.Description)
                .Prefix(Word)
                .Fuzzy(f => f
                    .Fuzziness(Fuzziness.Auto)
                    )
                    .Size(5)
                )
            )
        );

```

I don't know why response no has any results.  
What I must be do?

---

<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:** [November 16, 2017, 11:52pm UTC](https://discuss.elastic.co/t/using-nest-no-results/106191/12 "2017-11-16T23:52:14Z")

</div>

> [@parsa](#):
>
> ```auto
> Subject = new CompletionField
> {
> Input = new[] { Word },
> Weight = 5
> },
> Description = new CompletionField
> {
> Input = new[] { Word },
> Weight = 5
> }
> 
> ```

Rather than creating two completion fields, you may consider including multiple inputs into one completion field.

> [@parsa](#):
>
> ```auto
> .Completion("suggested_titles", cs =&gt; cs
> .Field(f => f.Subject).Field(x=>x.Description)
> 
> ```

You **can't** chain multiple successive calls to `.Field()`; a suggester operates on a single field, but you can send multiple suggesters in one request e.g.

```auto
var response = client.Search<Video>(s => s
    .Index("my_video")
    .Suggest(su => su
        .Completion("suggested_subjects", cs => cs
            .Field(f => f.Subject)
            .Prefix(Word)
            .Fuzzy(f => f
                .Fuzziness(Fuzziness.Auto)
                )
                .Size(5)
            )
        )
        .Completion("suggested_descriptions", cs => cs
            .Field(x => x.Description)
            .Prefix(Word)
            .Fuzzy(f => f
                .Fuzziness(Fuzziness.Auto)
                )
                .Size(5)
            )
        )
    );

```

Consider whether this is really what you want though, as opposed to using one `completion` field with multiple inputs.

Completion suggesters are designed for performance to be used in "provide suggestions as you type" scenarios e.g. autocompletion, but they are more limited in _"search expressiveness"_ compared to forming a comprehensive search strategy leveraging different [analysis](https://www.elastic.co/guide/en/elasticsearch/reference/current/analysis.html) on multiple fields. They may fit your use case perfectly or they may form part of your approach to your search problem.

> [@parsa](#):
>
> I don't know why response no has any results.
> 
> What I must be do?

I would recommend having a look at the [troubleshooting section](https://www.elastic.co/guide/en/elasticsearch/client/net-api/current/troubleshooting.html) to see what is going to and coming from Elasticsearch. Make sure that any existing `"my_video"` index is deleted before creating a new index with the same name and different mappings.

---

<div class="post-metadata">

**Author:** ![parsa](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/parsa/32/23227_2.png) [@parsa](https://discuss.elastic.co/u/parsa)\
**Post date:** [November 20, 2017, 6:38pm UTC](https://discuss.elastic.co/t/using-nest-no-results/106191/13 "2017-11-20T18:38:40Z")

</div>

With making debugging as you recommendation, I just replace response variable with this :

```
        var response = client.Search<Video>(s => s
        .MatchAll()
        );

```

and it returns this Error:

> Error converting value "بهترین روش برای بازکردن موز " to type 'Nest.CompletionField'. Path 'hits.hits[0].\_source.subject

---

<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:** [November 20, 2017, 8:21pm UTC](https://discuss.elastic.co/t/using-nest-no-results/106191/14 "2017-11-20T20:21:01Z")

</div>

> [@parsa](#):
>
> Error converting value "بهترین روش برای بازکردن موز " to type 'Nest.CompletionField'. Path 'hits.hits[0].\_source.subject

That indicates that the mapping in the index for type `Video` does not align the with POCO structure. In order to change the field mapping for a POCO property, you should delete the index and create it again with the correct mapping.

---

<div class="post-metadata">

**Author:** ![parsa](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/parsa/32/23227_2.png) [@parsa](https://discuss.elastic.co/u/parsa)\
**Post date:** [November 28, 2017, 2:34pm UTC](https://discuss.elastic.co/t/using-nest-no-results/106191/15 "2017-11-28T14:34:31Z")

</div>

> [@forloop](#):
>
> POCO property

I couldn't find any solution for making POCO structure base on my columns type for autocomplete.  
How can I do?

---

<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:** [November 28, 2017, 8:57pm UTC](https://discuss.elastic.co/t/using-nest-no-results/106191/16 "2017-11-28T20:57:42Z")

</div>

> [@parsa](#):
>
> I couldn't find any solution for making POCO structure base on my columns type for autocomplete.
> 
> How can I do?

Using the `CompletionField` type as the property, as per previous answers and examples.

---

<div class="post-metadata">

**Author:** ![parsa](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/parsa/32/23227_2.png) [@parsa](https://discuss.elastic.co/u/parsa)\
**Post date:** [November 29, 2017, 4:28pm UTC](https://discuss.elastic.co/t/using-nest-no-results/106191/17 "2017-11-29T16:28:45Z")

</div>

I do that, the response has this result :

> Valid NEST response built from a successful low level call on POST: /my\_videos/my\_video/\_search

but the count of results is 0.

---

<div class="post-metadata">

**Author:** ![parsa](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/parsa/32/23227_2.png) [@parsa](https://discuss.elastic.co/u/parsa)\
**Post date:** [December 4, 2017, 2:53pm UTC](https://discuss.elastic.co/t/using-nest-no-results/106191/18 "2017-12-04T14:53:10Z")

</div>

Can you help me?  
What I can do?  
Any Recommendation?  
I do that as this answer but counts of results is zero.

---

<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:** [December 4, 2017, 10:26pm UTC](https://discuss.elastic.co/t/using-nest-no-results/106191/19 "2017-12-04T22:26:28Z")

</div>

Let's break it down:

1. The request to Elasticsearch is successful as indicated by the `DebugInformation`:

> Valid NEST response built from a successful low level call on POST: /my\_videos/my\_video/\_search

1. The count of results is 0

This could for a number of reasons:

1. There is no data indexed in Elasticsearch. A quick search against `GET /_search` should determine whether this is true or not.
2. There is data indexed in Elasticsearch, _but_ it is either not in the index `my_videos`, or is not of the type `my_video`. Again, a `match_all` query search against `GET /my_videos/my_video/_search` and whether it returns results should rule this out.
3. No documents match the query that is being executed. From previous posts, we know that the query being executed is valid, so perhaps there is a problem in the query logic. This can be investigated during development by logging out all requests and responses by passing a delegate to [`OnRequestCompleted()` on `ConnectionSettings`](https://www.elastic.co/guide/en/elasticsearch/client/net-api/current/logging-with-on-request-completed.html), and writing them out somewhere e.g. to `Trace`, `Console`, file, etc.

I would suggest exploring these avenues.

---

<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:** [January 1, 2018, 10:26pm UTC](https://discuss.elastic.co/t/using-nest-no-results/106191/20 "2018-01-01T22:26:33Z")

</div>

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