# Searching with Elasticsearch.Net

**URL:** <https://discuss.elastic.co/t/searching-with-elasticsearch-net/21563>\
**Category:** Elasticsearch\
**Created:** [January 9, 2015, 5:43pm UTC](https://discuss.elastic.co/t/searching-with-elasticsearch-net/21563 "2015-01-09T17:43:36Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Garrett\_Johnson](https://avatars.discourse-cdn.com/v4/letter/g/41988e/32.png) [@Garrett\_Johnson](https://discuss.elastic.co/u/Garrett_Johnson)\
**Post date:** [January 9, 2015, 5:43pm UTC](https://discuss.elastic.co/t/searching-with-elasticsearch-net/21563/1 "2015-01-09T17:43:36Z")

</div>

Hi All,

I would like to use [Elasticsearch.Net](http://Elasticsearch.Net) (NEST requires types and I do not  
want strong types) to do a simple \_all term search. I can do this using  
the plugin elasticsearch head and I retrieve the appropriate documents.  
Here is some simple code I wrote just to say hey give me all that match.

var node = new Uri([http://myhost:9200](http://myhost:9200));

var config = new ConnectionConfiguration(node);

var exposed = config.ExposeRawResponse(true);

var client = new ElasticsearchClient(config);

var search = new

{

size = 10,

from = 1 \* 10,

query = new { query\_string = new { query = this.textBox1.Text } },

};

var searchResponse = client.Search("jdbc",search);

This returns these results:

{StatusCode: 200,  
Method: POST,  
Url: [http://u4vmeqlditapp01:9200/jdbc/\_search](http://u4vmeqlditapp01:9200/jdbc/_search),  
Request:  
{"size":10,"from":10,"query":{"query\_string":{"query":"Garrett"}}},  
Response:  
{"took":5,"timed\_out":false,"\_shards":{"total":5,"successful":5,"failed":0},"hits":{"total":10,"max\_score":1.1672286,"hits":[]}}}

But no documents.

Here is the JSON I'm trying to replicate:

- "query": {
  - "bool": {
    - "must": [
      - {
        - "query\_string": {
          - "default\_field": "\_all",
          - "query": "Garrett"  
}  
}  
],

    - "must\_not": [],
    - "should": []  
}  
},

- "from": 0,
- "size": 25000,
- "sort": [],
- "facets": { }

I'm pretty sure it is because the query doesn't have the default\_field set  
to \_all... But I don't know how to set that. I've tried several string  
concatenations to no avail.... it just searched for them.

Any one with any ideas. I want to simply search all types for a single  
string.

Garrett

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/997e2467-78f2-4d28-af49-1bd586df0145%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/997e2467-78f2-4d28-af49-1bd586df0145%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![Garrett\_Johnson](https://avatars.discourse-cdn.com/v4/letter/g/41988e/32.png) [@Garrett\_Johnson](https://discuss.elastic.co/u/Garrett_Johnson)\
**Post date:** [January 9, 2015, 5:54pm UTC](https://discuss.elastic.co/t/searching-with-elasticsearch-net/21563/2 "2015-01-09T17:54:11Z")

</div>

{ query = this.textBox1.Text,

default\_field = "\_all"

},

This seems to send it. Still don't know how to get the results.

It's like it should be in a foreach(hit in hits) {get fields} but I have  
nothing and documentation isn't helping.

On Friday, January 9, 2015 at 12:43:36 PM UTC-5, Garrett Johnson wrote:

> Hi All,
> 
> I would like to use [Elasticsearch.Net](http://Elasticsearch.Net) (NEST requires types and I do not  
> want strong types) to do a simple \_all term search. I can do this using  
> the plugin elasticsearch head and I retrieve the appropriate documents.  
> Here is some simple code I wrote just to say hey give me all that match.
> 
> var node = new Uri([http://myhost:9200](http://myhost:9200));
> 
> var config = new ConnectionConfiguration(node);
> 
> var exposed = config.ExposeRawResponse(true);
> 
> var client = new ElasticsearchClient(config);
> 
> var search = new
> 
> {
> 
> size = 10,
> 
> from = 1 \* 10,
> 
> query = new { query\_string = new { query = this.textBox1.Text } },
> 
> };
> 
> var searchResponse = client.Search("jdbc",search);
> 
> This returns these results:
> 
> {StatusCode: 200,  
> Method: POST,  
> Url: [http://u4vmeqlditapp01:9200/jdbc/\_search](http://u4vmeqlditapp01:9200/jdbc/_search),  
> Request:  
> {"size":10,"from":10,"query":{"query\_string":{"query":"Garrett"}}},  
> Response:  
> {"took":5,"timed\_out":false,"\_shards":{"total":5,"successful":5,"failed":0},"hits":{"total":10,"max\_score":1.1672286,"hits":}}}
> 
> But no documents.
> 
> Here is the JSON I'm trying to replicate:
> 
> - "query": {
> - "bool": {
> - "must": [
> - {
> - "query\_string": {
> - "default\_field": "\_all",
> - "query": "Garrett"  
> }  
> }  
> ],
> 
> - "must\_not": ,
> - "should":   
> }  
> },
> 
> - "from": 0,
> - "size": 25000,
> - "sort": ,
> - "facets": { }
> 
> I'm pretty sure it is because the query doesn't have the default\_field set  
> to \_all... But I don't know how to set that. I've tried several string  
> concatenations to no avail.... it just searched for them.
> 
> Any one with any ideas. I want to simply search all types for a single  
> string.
> 
> Garrett

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/c7be81ac-d3ff-4841-b458-41aae34df921%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/c7be81ac-d3ff-4841-b458-41aae34df921%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![Itamar\_Syn\_Hershko](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/itamar_syn_hershko/32/725_2.png) [@Itamar\_Syn\_Hershko](https://discuss.elastic.co/u/Itamar_Syn_Hershko)\
**Post date:** [January 9, 2015, 5:56pm UTC](https://discuss.elastic.co/t/searching-with-elasticsearch-net/21563/3 "2015-01-09T17:56:20Z")

</div>

If all you need is querying, I will highly recommend looking at  
[GitHub - ElasticLINQ/ElasticLINQ: Use LINQ to query Elasticsearch with results as .NET objects](https://github.com/CenturyLinkCloud/ElasticLINQ) for .NET

I also have my own stab at a .NET client library for Elasticsearch here:  
[GitHub - synhershko/NElasticsearch: An alternative Elasticsearch client for .NET, built on-the-go while working on real-world projects](https://github.com/synhershko/NElasticsearch) /  
[NuGet Gallery | NElasticsearch 1.0.14](https://www.nuget.org/packages/NElasticsearch/1.0.14) (still WIP)

--

Itamar Syn-Hershko  
[http://code972.com](http://code972.com) | @synhershko [https://twitter.com/synhershko](https://twitter.com/synhershko)  
Freelance Developer & Consultant  
Author of RavenDB in Action [http://manning.com/synhershko/](http://manning.com/synhershko/)

On Fri, Jan 9, 2015 at 7:54 PM, Garrett Johnson [garrettcjohnson@gmail.com](mailto:garrettcjohnson@gmail.com)  
wrote:

> { query = this.textBox1.Text,
> 
> default\_field = "\_all"
> 
> },
> 
> This seems to send it. Still don't know how to get the results.
> 
> It's like it should be in a foreach(hit in hits) {get fields} but I have  
> nothing and documentation isn't helping.
> 
> On Friday, January 9, 2015 at 12:43:36 PM UTC-5, Garrett Johnson wrote:
> 
> > Hi All,
> > 
> > I would like to use [Elasticsearch.Net](http://Elasticsearch.Net) (NEST requires types and I do not  
> > want strong types) to do a simple \_all term search. I can do this using  
> > the plugin elasticsearch head and I retrieve the appropriate documents.  
> > Here is some simple code I wrote just to say hey give me all that match.
> > 
> > var node = new Uri([http://myhost:9200](http://myhost:9200));
> > 
> > var config = new ConnectionConfiguration(node);
> > 
> > var exposed = config.ExposeRawResponse(true);
> > 
> > var client = new ElasticsearchClient(config);
> > 
> > var search = new
> > 
> > {
> > 
> > size = 10,
> > 
> > from = 1 \* 10,
> > 
> > query = new { query\_string = new { query = this.textBox1.Text } },
> > 
> > };
> > 
> > var searchResponse = client.Search("jdbc",search);
> > 
> > This returns these results:
> > 
> > {StatusCode: 200,  
> > Method: POST,  
> > Url: [http://u4vmeqlditapp01:9200/jdbc/\_search](http://u4vmeqlditapp01:9200/jdbc/_search),  
> > Request: {"size":10,"from":10,"query":{"query\_string":{"query":"Garrett"}}},
> > 
> > Response: {"took":5,"timed\_out":false,"\_shards":{"total":5,"  
> > successful":5,"failed":0},"hits":{"total":10,"max\_score":  
> > 1.1672286,"hits":}}}
> > 
> > But no documents.
> > 
> > Here is the JSON I'm trying to replicate:
> > 
> > - "query": {
> > - "bool": {
> > - "must": [
> > - {
> > - "query\_string": {
> > - "default\_field": "\_all",
> > - "query": "Garrett"  
> > }  
> > }  
> > ],
> > 
> > - "must\_not": ,
> > - "should":   
> > }  
> > },
> > 
> > - "from": 0,
> > - "size": 25000,
> > - "sort": ,
> > - "facets": { }
> > 
> > I'm pretty sure it is because the query doesn't have the default\_field  
> > set to \_all... But I don't know how to set that. I've tried several string  
> > concatenations to no avail.... it just searched for them.
> > 
> > Any one with any ideas. I want to simply search all types for a single  
> > string.
> > 
> > Garrett
> > 
> > --  
> > You received this message because you are subscribed to the Google Groups  
> > "elasticsearch" group.  
> > To unsubscribe from this group and stop receiving emails from it, send an  
> > email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
> > To view this discussion on the web visit  
> > [https://groups.google.com/d/msgid/elasticsearch/c7be81ac-d3ff-4841-b458-41aae34df921%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/c7be81ac-d3ff-4841-b458-41aae34df921%40googlegroups.com)  
> > [https://groups.google.com/d/msgid/elasticsearch/c7be81ac-d3ff-4841-b458-41aae34df921%40googlegroups.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/c7be81ac-d3ff-4841-b458-41aae34df921%40googlegroups.com?utm_medium=email&utm_source=footer)  
> > .  
> > For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/CAHTr4ZtOWzNT6to0H5ahDooJ-J%3DAgLhRcJxdJwUwCB3i7wjLeg%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CAHTr4ZtOWzNT6to0H5ahDooJ-J%3DAgLhRcJxdJwUwCB3i7wjLeg%40mail.gmail.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![daflookie](https://avatars.discourse-cdn.com/v4/letter/d/46a35a/32.png) [@daflookie](https://discuss.elastic.co/u/daflookie)\
**Post date:** [January 10, 2015, 11:27am UTC](https://discuss.elastic.co/t/searching-with-elasticsearch-net/21563/4 "2015-01-10T11:27:03Z")

</div>

I think you are just getting unlucky. You are asking for the top 10  
results, starting \*after \*result number 10. Only problem is the search  
response is saying there is only 10 results total, so there are no hits to  
return.

Try changing your from to 0, instead of 1 \* 10. Or you can just omit that  
all together, as ES will default to 0.

If you are coming from the world of sql, one difference in simple queries  
is ES gives back the total number of results with that total property you  
see in the response's hits section. So even if you ask for only 10  
documents, total will give you the full count no matter what.

Steve

On Friday, January 9, 2015 at 12:43:36 PM UTC-5, Garrett Johnson wrote:

> Hi All,
> 
> I would like to use [Elasticsearch.Net](http://Elasticsearch.Net) (NEST requires types and I do not  
> want strong types) to do a simple \_all term search. I can do this using  
> the plugin elasticsearch head and I retrieve the appropriate documents.  
> Here is some simple code I wrote just to say hey give me all that match.
> 
> var node = new Uri([http://myhost:9200](http://myhost:9200));
> 
> var config = new ConnectionConfiguration(node);
> 
> var exposed = config.ExposeRawResponse(true);
> 
> var client = new ElasticsearchClient(config);
> 
> var search = new
> 
> {
> 
> size = 10,
> 
> from = 1 \* 10,
> 
> query = new { query\_string = new { query = this.textBox1.Text } },
> 
> };
> 
> var searchResponse = client.Search("jdbc",search);
> 
> This returns these results:
> 
> {StatusCode: 200,  
> Method: POST,  
> Url: [http://u4vmeqlditapp01:9200/jdbc/\_search](http://u4vmeqlditapp01:9200/jdbc/_search),  
> Request:  
> {"size":10,"from":10,"query":{"query\_string":{"query":"Garrett"}}},  
> Response:  
> {"took":5,"timed\_out":false,"\_shards":{"total":5,"successful":5,"failed":0},"hits":{"total":10,"max\_score":1.1672286,"hits":}}}
> 
> But no documents.
> 
> Here is the JSON I'm trying to replicate:
> 
> - "query": {
> - "bool": {
> - "must": [
> - {
> - "query\_string": {
> - "default\_field": "\_all",
> - "query": "Garrett"  
> }  
> }  
> ],
> 
> - "must\_not": ,
> - "should":   
> }  
> },
> 
> - "from": 0,
> - "size": 25000,
> - "sort": ,
> - "facets": { }
> 
> I'm pretty sure it is because the query doesn't have the default\_field set  
> to \_all... But I don't know how to set that. I've tried several string  
> concatenations to no avail.... it just searched for them.
> 
> Any one with any ideas. I want to simply search all types for a single  
> string.
> 
> Garrett

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/b4c0a2ac-acdb-43fb-a238-88520a4c1be5%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/b4c0a2ac-acdb-43fb-a238-88520a4c1be5%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![Garrett\_Johnson](https://avatars.discourse-cdn.com/v4/letter/g/41988e/32.png) [@Garrett\_Johnson](https://discuss.elastic.co/u/Garrett_Johnson)\
**Post date:** [January 13, 2015, 3:35am UTC](https://discuss.elastic.co/t/searching-with-elasticsearch-net/21563/5 "2015-01-13T03:35:48Z")

</div>

Ok that worked. Sort of. I can see the results in the response now.

However I'm not able to refer to hits. I can see them but there isn't a  
hit or hits type to refer to so I can see what is in a hit.

string? myid = searchResponse.Response.hits.hits[1].nestedObject["id"].myid  
Doesn't work.

Trying to follow this guide here  
[http://nest.azurewebsites.net/elasticsearch-net/handling-responses.html](http://nest.azurewebsites.net/elasticsearch-net/handling-responses.html)  
and hits isn't a member/method or type.

When I try to refer to hits i get this...

Error 2 'Elasticsearch.Net.DynamicDictionary' does not contain a definition  
for 'hits' and no extension method 'hits' accepting a first argument of  
type 'Elasticsearch.Net.DynamicDictionary' could be are you missing a using  
directive or an assembly  
reference?) C:\Users\Garrett\_Johnson\documents\visual studio  
2013\Projects\SearchTest\SearchTest\main.cs 56 52 SearchTest

On Saturday, January 10, 2015 at 6:27:03 AM UTC-5, Steve Flook wrote:

> I think you are just getting unlucky. You are asking for the top 10  
> results, starting \*after \*result number 10. Only problem is the search  
> response is saying there is only 10 results total, so there are no hits to  
> return.
> 
> Try changing your from to 0, instead of 1 \* 10. Or you can just omit  
> that all together, as ES will default to 0.
> 
> If you are coming from the world of sql, one difference in simple queries  
> is ES gives back the total number of results with that total property you  
> see in the response's hits section. So even if you ask for only 10  
> documents, total will give you the full count no matter what.
> 
> Steve
> 
> On Friday, January 9, 2015 at 12:43:36 PM UTC-5, Garrett Johnson wrote:
> 
> > Hi All,
> > 
> > I would like to use [Elasticsearch.Net](http://Elasticsearch.Net) (NEST requires types and I do not  
> > want strong types) to do a simple \_all term search. I can do this using  
> > the plugin elasticsearch head and I retrieve the appropriate documents.  
> > Here is some simple code I wrote just to say hey give me all that match.
> > 
> > var node = new Uri([http://myhost:9200](http://myhost:9200));
> > 
> > var config = new ConnectionConfiguration(node);
> > 
> > var exposed = config.ExposeRawResponse(true);
> > 
> > var client = new ElasticsearchClient(config);
> > 
> > var search = new
> > 
> > {
> > 
> > size = 10,
> > 
> > from = 1 \* 10,
> > 
> > query = new { query\_string = new { query = this.textBox1.Text } },
> > 
> > };
> > 
> > var searchResponse = client.Search("jdbc",search);
> > 
> > This returns these results:
> > 
> > {StatusCode: 200,  
> > Method: POST,  
> > Url: [http://u4vmeqlditapp01:9200/jdbc/\_search](http://u4vmeqlditapp01:9200/jdbc/_search),  
> > Request:  
> > {"size":10,"from":10,"query":{"query\_string":{"query":"Garrett"}}},  
> > Response:  
> > {"took":5,"timed\_out":false,"\_shards":{"total":5,"successful":5,"failed":0},"hits":{"total":10,"max\_score":1.1672286,"hits":}}}
> > 
> > But no documents.
> > 
> > Here is the JSON I'm trying to replicate:
> > 
> > - "query": {
> > - "bool": {
> > - "must": [
> > - {
> > - "query\_string": {
> > - "default\_field": "\_all",
> > - "query": "Garrett"  
> > }  
> > }  
> > ],
> > 
> > - "must\_not": ,
> > - "should":   
> > }  
> > },
> > 
> > - "from": 0,
> > - "size": 25000,
> > - "sort": ,
> > - "facets": { }
> > 
> > I'm pretty sure it is because the query doesn't have the default\_field  
> > set to \_all... But I don't know how to set that. I've tried several string  
> > concatenations to no avail.... it just searched for them.
> > 
> > Any one with any ideas. I want to simply search all types for a single  
> > string.
> > 
> > Garrett

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/ef61025c-a740-4c90-b514-0f823bdd0b07%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/ef61025c-a740-4c90-b514-0f823bdd0b07%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![Garrett\_Johnson](https://avatars.discourse-cdn.com/v4/letter/g/41988e/32.png) [@Garrett\_Johnson](https://discuss.elastic.co/u/Garrett_Johnson)\
**Post date:** [January 13, 2015, 3:37am UTC](https://discuss.elastic.co/t/searching-with-elasticsearch-net/21563/6 "2015-01-13T03:37:00Z")

</div>

Ok that worked. Sort of. I can see the results in the response now.

However I'm not able to refer to hits. I can see them but there isn't a  
hit or hits type to refer to so I can see what is in a hit.

string? myid = searchResponse.Response.hits.hits[1].nestedObject["id"].myid  
Doesn't work.

Trying to follow this guide here  
[http://nest.azurewebsites.net/elasticsearch-net/handling-responses.html](http://nest.azurewebsites.net/elasticsearch-net/handling-responses.html)  
and hits isn't a member/method or type.

When I try to refer to hits i get this...

Error 2 'Elasticsearch.Net.DynamicDictionary' does not contain a definition  
for 'hits' and no extension method 'hits' accepting a first argument of  
type 'Elasticsearch.Net.DynamicDictionary' could be are you missing a using  
directive or an assembly  
reference?) C:\pathtoproject\main.cs 56 52 SearchTest

On Saturday, January 10, 2015 at 6:27:03 AM UTC-5, Steve Flook wrote:

> I think you are just getting unlucky. You are asking for the top 10  
> results, starting \*after \*result number 10. Only problem is the search  
> response is saying there is only 10 results total, so there are no hits to  
> return.
> 
> Try changing your from to 0, instead of 1 \* 10. Or you can just omit  
> that all together, as ES will default to 0.
> 
> If you are coming from the world of sql, one difference in simple queries  
> is ES gives back the total number of results with that total property you  
> see in the response's hits section. So even if you ask for only 10  
> documents, total will give you the full count no matter what.
> 
> Steve
> 
> On Friday, January 9, 2015 at 12:43:36 PM UTC-5, Garrett Johnson wrote:
> 
> > Hi All,
> > 
> > I would like to use [Elasticsearch.Net](http://Elasticsearch.Net) (NEST requires types and I do not  
> > want strong types) to do a simple \_all term search. I can do this using  
> > the plugin elasticsearch head and I retrieve the appropriate documents.  
> > Here is some simple code I wrote just to say hey give me all that match.
> > 
> > var node = new Uri([http://myhost:9200](http://myhost:9200));
> > 
> > var config = new ConnectionConfiguration(node);
> > 
> > var exposed = config.ExposeRawResponse(true);
> > 
> > var client = new ElasticsearchClient(config);
> > 
> > var search = new
> > 
> > {
> > 
> > size = 10,
> > 
> > from = 1 \* 10,
> > 
> > query = new { query\_string = new { query = this.textBox1.Text } },
> > 
> > };
> > 
> > var searchResponse = client.Search("jdbc",search);
> > 
> > This returns these results:
> > 
> > {StatusCode: 200,  
> > Method: POST,  
> > Url: [http://u4vmeqlditapp01:9200/jdbc/\_search](http://u4vmeqlditapp01:9200/jdbc/_search),  
> > Request:  
> > {"size":10,"from":10,"query":{"query\_string":{"query":"Garrett"}}},  
> > Response:  
> > {"took":5,"timed\_out":false,"\_shards":{"total":5,"successful":5,"failed":0},"hits":{"total":10,"max\_score":1.1672286,"hits":}}}
> > 
> > But no documents.
> > 
> > Here is the JSON I'm trying to replicate:
> > 
> > - "query": {
> > - "bool": {
> > - "must": [
> > - {
> > - "query\_string": {
> > - "default\_field": "\_all",
> > - "query": "Garrett"  
> > }  
> > }  
> > ],
> > 
> > - "must\_not": ,
> > - "should":   
> > }  
> > },
> > 
> > - "from": 0,
> > - "size": 25000,
> > - "sort": ,
> > - "facets": { }
> > 
> > I'm pretty sure it is because the query doesn't have the default\_field  
> > set to \_all... But I don't know how to set that. I've tried several string  
> > concatenations to no avail.... it just searched for them.
> > 
> > Any one with any ideas. I want to simply search all types for a single  
> > string.
> > 
> > Garrett

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/2d83b245-5eef-4948-b1f1-df0a5cbf1950%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/2d83b245-5eef-4948-b1f1-df0a5cbf1950%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![Garrett\_Johnson](https://avatars.discourse-cdn.com/v4/letter/g/41988e/32.png) [@Garrett\_Johnson](https://discuss.elastic.co/u/Garrett_Johnson)\
**Post date:** [January 14, 2015, 1:57am UTC](https://discuss.elastic.co/t/searching-with-elasticsearch-net/21563/7 "2015-01-14T01:57:11Z")

</div>

Getting closer:

I converted my searchResponse to a var

i can now refer to a value like this:

(((dynamic)dyndist).hits.hits[1]).Value.\_source.Id  
This works great and if I put a 2 there it works and returns the second  
item.

Ok that's all well and good however. I cannot do something like this:

var dyndist = new Elasticsearch.Net.DynamicDictionary();  
dyndist = searchResponse.Response;  
long maxhit;  
maxhit = ((dynamic)dyndist).hits.total.Value; //this does get the # of hits  
for (int hitpos = 1 ; hitpos \<= maxhit; hitpos ++)  
{  
//just creating a string here but I would  
theid = theid + ":" +  
(((dynamic)dyndist).hits.hits[hitpos]).Value.\_source.Id; //id is my id not  
the id from Elasticsearch  
}

I get this error:

An unhandled exception of type  
'Microsoft.CSharp.RuntimeBinder.RuntimeBinderException' occurred in  
System.Core.dll  
Additional information: Cannot perform runtime binding on a null reference

If I switch that hitpos to a 1 it works fine and returns the 1 value. i  
want to get them all somehow..

Any ideas.

I tried converting to a List but only .Values is a List seems I can't  
convert hits.hits. Stuck here for now ☹

On Monday, January 12, 2015 at 10:37:00 PM UTC-5, GWired wrote:

> Ok that worked. Sort of. I can see the results in the response now.
> 
> However I'm not able to refer to hits. I can see them but there isn't a  
> hit or hits type to refer to so I can see what is in a hit.
> 
> string? myid = searchResponse.Response.hits.hits[1].nestedObject["id"  
> ].myid  
> Doesn't work.
> 
> Trying to follow this guide here  
> [http://nest.azurewebsites.net/elasticsearch-net/handling-responses.html](http://nest.azurewebsites.net/elasticsearch-net/handling-responses.html)  
> and hits isn't a member/method or type.
> 
> When I try to refer to hits i get this...
> 
> Error 2 'Elasticsearch.Net.DynamicDictionary' does not contain a  
> definition for 'hits' and no extension method 'hits' accepting a first  
> argument of type 'Elasticsearch.Net.DynamicDictionary' could be are you  
> missing a using directive or an assembly  
> reference?) C:\pathtoproject\main.cs 56 52 SearchTest
> 
> On Saturday, January 10, 2015 at 6:27:03 AM UTC-5, Steve Flook wrote:
> 
> > I think you are just getting unlucky. You are asking for the top 10  
> > results, starting \*after \*result number 10. Only problem is the search  
> > response is saying there is only 10 results total, so there are no hits to  
> > return.
> > 
> > Try changing your from to 0, instead of 1 \* 10. Or you can just omit  
> > that all together, as ES will default to 0.
> > 
> > If you are coming from the world of sql, one difference in simple queries  
> > is ES gives back the total number of results with that total property  
> > you see in the response's hits section. So even if you ask for only 10  
> > documents, total will give you the full count no matter what.
> > 
> > Steve
> > 
> > On Friday, January 9, 2015 at 12:43:36 PM UTC-5, Garrett Johnson wrote:
> > 
> > > Hi All,
> > > 
> > > I would like to use [Elasticsearch.Net](http://Elasticsearch.Net) (NEST requires types and I do not  
> > > want strong types) to do a simple \_all term search. I can do this using  
> > > the plugin elasticsearch head and I retrieve the appropriate documents.  
> > > Here is some simple code I wrote just to say hey give me all that match.
> > > 
> > > var node = new Uri([http://myhost:9200](http://myhost:9200));
> > > 
> > > var config = new ConnectionConfiguration(node);
> > > 
> > > var exposed = config.ExposeRawResponse(true);
> > > 
> > > var client = new ElasticsearchClient(config);
> > > 
> > > var search = new
> > > 
> > > {
> > > 
> > > size = 10,
> > > 
> > > from = 1 \* 10,
> > > 
> > > query = new { query\_string = new { query = this.textBox1.Text } },
> > > 
> > > };
> > > 
> > > var searchResponse = client.Search("jdbc",search);
> > > 
> > > This returns these results:
> > > 
> > > {StatusCode: 200,  
> > > Method: POST,  
> > > Url: [http://u4vmeqlditapp01:9200/jdbc/\_search](http://u4vmeqlditapp01:9200/jdbc/_search),  
> > > Request:  
> > > {"size":10,"from":10,"query":{"query\_string":{"query":"Garrett"}}},  
> > > Response:  
> > > {"took":5,"timed\_out":false,"\_shards":{"total":5,"successful":5,"failed":0},"hits":{"total":10,"max\_score":1.1672286,"hits":}}}
> > > 
> > > But no documents.
> > > 
> > > Here is the JSON I'm trying to replicate:
> > > 
> > > - "query": {
> > > - "bool": {
> > > - "must": [
> > > - {
> > > - "query\_string": {
> > > - "default\_field": "\_all",
> > > - "query": "Garrett"  
> > > }  
> > > }  
> > > ],
> > > 
> > > - "must\_not": ,
> > > - "should":   
> > > }  
> > > },
> > > 
> > > - "from": 0,
> > > - "size": 25000,
> > > - "sort": ,
> > > - "facets": { }
> > > 
> > > I'm pretty sure it is because the query doesn't have the default\_field  
> > > set to \_all... But I don't know how to set that. I've tried several string  
> > > concatenations to no avail.... it just searched for them.
> > > 
> > > Any one with any ideas. I want to simply search all types for a single  
> > > string.
> > > 
> > > Garrett

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/f4d6beb4-601c-4460-9a61-2850a8f00800%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/f4d6beb4-601c-4460-9a61-2850a8f00800%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![Garrett\_Johnson](https://avatars.discourse-cdn.com/v4/letter/g/41988e/32.png) [@Garrett\_Johnson](https://discuss.elastic.co/u/Garrett_Johnson)\
**Post date:** [January 14, 2015, 2:04am UTC](https://discuss.elastic.co/t/searching-with-elasticsearch-net/21563/8 "2015-01-14T02:04:12Z")

</div>

-\> slaps forhead

oboe... hitpos should start at 0 not 1

got my results now converting to DG 🙂

I will post final code once done.

On Tuesday, January 13, 2015 at 8:57:11 PM UTC-5, GWired wrote:

> Getting closer:
> 
> I converted my searchResponse to a var
> 
> i can now refer to a value like this:
> 
> (((dynamic)dyndist).hits.hits[1]).Value.\_source.Id  
> This works great and if I put a 2 there it works and returns the second  
> item.
> 
> Ok that's all well and good however. I cannot do something like this:
> 
> var dyndist = new Elasticsearch.Net.DynamicDictionary();  
> dyndist = searchResponse.Response;  
> long maxhit;  
> maxhit = ((dynamic)dyndist).hits.total.Value; //this does get the # of  
> hits  
> for (int hitpos = 1 ; hitpos \<= maxhit; hitpos ++)  
> {  
> //just creating a string here but I would  
> theid = theid + ":" +  
> (((dynamic)dyndist).hits.hits[hitpos]).Value.\_source.Id; //id is my id not  
> the id from Elasticsearch  
> }
> 
> I get this error:
> 
> An unhandled exception of type  
> 'Microsoft.CSharp.RuntimeBinder.RuntimeBinderException' occurred in  
> System.Core.dll  
> Additional information: Cannot perform runtime binding on a null reference
> 
> If I switch that hitpos to a 1 it works fine and returns the 1 value. i  
> want to get them all somehow..
> 
> Any ideas.
> 
> I tried converting to a List but only .Values is a List seems I can't  
> convert hits.hits. Stuck here for now ☹
> 
> On Monday, January 12, 2015 at 10:37:00 PM UTC-5, GWired wrote:
> 
> > Ok that worked. Sort of. I can see the results in the response now.
> > 
> > However I'm not able to refer to hits. I can see them but there isn't a  
> > hit or hits type to refer to so I can see what is in a hit.
> > 
> > string? myid = searchResponse.Response.hits.hits[1].nestedObject["id"  
> > ].myid  
> > Doesn't work.
> > 
> > Trying to follow this guide here  
> > [http://nest.azurewebsites.net/elasticsearch-net/handling-responses.html](http://nest.azurewebsites.net/elasticsearch-net/handling-responses.html)  
> > and hits isn't a member/method or type.
> > 
> > When I try to refer to hits i get this...
> > 
> > Error 2 'Elasticsearch.Net.DynamicDictionary' does not contain a  
> > definition for 'hits' and no extension method 'hits' accepting a first  
> > argument of type 'Elasticsearch.Net.DynamicDictionary' could be are you  
> > missing a using directive or an assembly  
> > reference?) C:\pathtoproject\main.cs 56 52 SearchTest
> > 
> > On Saturday, January 10, 2015 at 6:27:03 AM UTC-5, Steve Flook wrote:
> > 
> > > I think you are just getting unlucky. You are asking for the top 10  
> > > results, starting \*after \*result number 10. Only problem is the search  
> > > response is saying there is only 10 results total, so there are no hits to  
> > > return.
> > > 
> > > Try changing your from to 0, instead of 1 \* 10. Or you can just omit  
> > > that all together, as ES will default to 0.
> > > 
> > > If you are coming from the world of sql, one difference in simple  
> > > queries is ES gives back the total number of results with that total  
> > > property you see in the response's hits section. So even if you ask  
> > > for only 10 documents, total will give you the full count no matter  
> > > what.
> > > 
> > > Steve
> > > 
> > > On Friday, January 9, 2015 at 12:43:36 PM UTC-5, Garrett Johnson wrote:
> > > 
> > > > Hi All,
> > > > 
> > > > I would like to use [Elasticsearch.Net](http://Elasticsearch.Net) (NEST requires types and I do not  
> > > > want strong types) to do a simple \_all term search. I can do this using  
> > > > the plugin elasticsearch head and I retrieve the appropriate documents.  
> > > > Here is some simple code I wrote just to say hey give me all that match.
> > > > 
> > > > var node = new Uri([http://myhost:9200](http://myhost:9200));
> > > > 
> > > > var config = new ConnectionConfiguration(node);
> > > > 
> > > > var exposed = config.ExposeRawResponse(true);
> > > > 
> > > > var client = new ElasticsearchClient(config);
> > > > 
> > > > var search = new
> > > > 
> > > > {
> > > > 
> > > > size = 10,
> > > > 
> > > > from = 1 \* 10,
> > > > 
> > > > query = new { query\_string = new { query = this.textBox1.Text } },
> > > > 
> > > > };
> > > > 
> > > > var searchResponse = client.Search("jdbc",search);
> > > > 
> > > > This returns these results:
> > > > 
> > > > {StatusCode: 200,  
> > > > Method: POST,  
> > > > Url: [http://u4vmeqlditapp01:9200/jdbc/\_search](http://u4vmeqlditapp01:9200/jdbc/_search),  
> > > > Request:  
> > > > {"size":10,"from":10,"query":{"query\_string":{"query":"Garrett"}}},  
> > > > Response:  
> > > > {"took":5,"timed\_out":false,"\_shards":{"total":5,"successful":5,"failed":0},"hits":{"total":10,"max\_score":1.1672286,"hits":}}}
> > > > 
> > > > But no documents.
> > > > 
> > > > Here is the JSON I'm trying to replicate:
> > > > 
> > > > - "query": {
> > > > - "bool": {
> > > > - "must": [
> > > > - {
> > > > - "query\_string": {
> > > > - "default\_field": "\_all",
> > > > - "query": "Garrett"  
> > > > }  
> > > > }  
> > > > ],
> > > > 
> > > > - "must\_not": ,
> > > > - "should":   
> > > > }  
> > > > },
> > > > 
> > > > - "from": 0,
> > > > - "size": 25000,
> > > > - "sort": ,
> > > > - "facets": { }
> > > > 
> > > > I'm pretty sure it is because the query doesn't have the default\_field  
> > > > set to \_all... But I don't know how to set that. I've tried several string  
> > > > concatenations to no avail.... it just searched for them.
> > > > 
> > > > Any one with any ideas. I want to simply search all types for a single  
> > > > string.
> > > > 
> > > > Garrett

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/fff7dbd7-2985-46d7-a816-ace1c6bf09d3%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/fff7dbd7-2985-46d7-a816-ace1c6bf09d3%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<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:** [July 6, 2017, 12:39am UTC](https://discuss.elastic.co/t/searching-with-elasticsearch-net/21563/9 "2017-07-06T00:39:08Z")

</div>


