# Help needed On Nest using OIS

**URL:** <https://discuss.elastic.co/t/help-needed-on-nest-using-ois/118938>\
**Category:** Elasticsearch\
**Created:** [February 7, 2018, 10:47pm UTC](https://discuss.elastic.co/t/help-needed-on-nest-using-ois/118938 "2018-02-07T22:47:18Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Joey\_Lu](https://avatars.discourse-cdn.com/v4/letter/j/2bfe46/32.png) [@Joey\_Lu](https://discuss.elastic.co/u/Joey_Lu)\
**Post date:** [February 7, 2018, 10:47pm UTC](https://discuss.elastic.co/t/help-needed-on-nest-using-ois/118938/1 "2018-02-07T22:47:18Z")

</div>

So I am doing a keyword searching using [Asp.Net](http://Asp.Net) and Elastic. This is my code (Dynamic Query):

```auto
public List<string> SearchFiles(string[] searchPattern, string indexName, string docType, DateTime date)
     {
      IEnumerable<string> searchPartterns = searchPattern.AsEnumerable();
   config.DefaultIndex(indexName);
      var response = client.Search<ElasticSearchFile>(new SearchRequest<ElasticSearchFile>
        {
       Query = new QueryContainer(new BoolQuery
             {
                   Must = BuildPhraseQueryContainer(searchPattern, docType),
                Should = new List<QueryContainer>{ new QueryContainer(new DateRangeQuery
                    {
                     Name = "date",
                         Field = "date",
                   GreaterThanOrEqualTo = date.ToString(DateFormat.year_month_day)
                       })
                     }
                  })
                });
                 var files = response.Documents;
               var result = (from f in files
                           select f.filename).ToList();
               return result;
             }
           private List<QueryContainer> BuildPhraseQueryContainer(string[] terms, string docType)
           {
               List<QueryContainer> _result = new List<QueryContainer>();
            QueryContainer line1 = new QueryContainer(new TermQuery
                {
                   Field = new Field("filetype"),
                      Value = docType.ToLower()
              });
                _result.Add(line1);
                foreach (string term in terms)
             {
                   QueryContainer result = new QueryContainer(new TermQuery
                  {
                        Field = new Field("_file_content"),
                         Value = term.ToLower()
                   });
                       _result.Add(result);
                }
                  return _result;
              }

```

config is a global ConnectionSettings and client is a global ElasticClient(config).

It worked fine yesterday and without any code change, today it stopped working. I got the debug info, it says it is a bad request. Here is the request string captured:

```
GET antra/elasticsearchfile/_search?
{
  {"query":
     {"bool":
      {"must":
         [
           {"term":
            {"filetype":{"value":"resume"}}
           },
          {"term":
            {"_file_content":{"value":"java"}}
          }
         ],
    "should":[
      {"range":
        {"date":{"gte":"90ear_0onA12_1a90","_name":"date"}}
        
      }
      ]
      
    }
    
  }
    
  }
}

```

Here is the error message:

> _Invalid NEST response built from a unsuccessful low level call on POST: /antra/elasticsearchfile/search?typed\_keys=true  
> # Audit trail of this API call:  
> \_ - [1] BadResponse: Node: [http://localhost:9200/](http://localhost:9200/) Took: 00:00:00.0580006_  
> _# OriginalException: System.Net.WebException: The remote server returned an error: (400) Bad Request._  
> \_ at System.Net.HttpWebRequest.GetResponse()\_  
> \_ at Elasticsearch.Net.HttpConnection.Request[TResponse](RequestData requestData) in c:\Projects\elastic\net-master\src\Elasticsearch.Net\Connection\HttpConnection.cs:line 167

I kinda know where the problem is but I do not know how to solve it. Here are my questions: 1. Why is it generating a POST (in error message) even I am trying to search? 2. How could I remove the 2nd outtest {} (around "query") to make my request valid?

I am using Elastic Search 5.5 and Nest 6.0

Thanks

---

<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:** [February 8, 2018, 7:27am UTC](https://discuss.elastic.co/t/help-needed-on-nest-using-ois/118938/2 "2018-02-08T07:27:36Z")

</div>

Nest 6.0 is not compatible with Elasticsearch 5.5. Please use the latest Nest 5.x, which at time of writing is 5.6.0 and let me know if your issue is resolved.

---

<div class="post-metadata">

**Author:** ![Joey\_Lu](https://avatars.discourse-cdn.com/v4/letter/j/2bfe46/32.png) [@Joey\_Lu](https://discuss.elastic.co/u/Joey_Lu)\
**Post date:** [February 8, 2018, 3:27pm UTC](https://discuss.elastic.co/t/help-needed-on-nest-using-ois/118938/3 "2018-02-08T15:27:48Z")

</div>

Thanks for the reply.  
I downgraded my NEST to 5.6.  
The problem still exists.  
However, when I remove my SHOULD, it worked. Looks like my Should query is having some issue. Is it the way of setting up kind of a cutting off time on search? If not (well, it has to be not since mine is not working), how should I write the Should part?

---

<div class="post-metadata">

**Author:** ![Joey\_Lu](https://avatars.discourse-cdn.com/v4/letter/j/2bfe46/32.png) [@Joey\_Lu](https://discuss.elastic.co/u/Joey_Lu)\
**Post date:** [February 8, 2018, 5:48pm UTC](https://discuss.elastic.co/t/help-needed-on-nest-using-ois/118938/4 "2018-02-08T17:48:46Z")

</div>

All right. I tried it out.  
Apparently the time format is the issue. I changed it to

```
QueryContainer lastLine = new QueryContainer(new DateRangeQuery
            {
                Name = "date",
                Field = "date",
                GreaterThanOrEqualTo = date.ToString(DateFormat.epoch_millis)
            });

```

and it worked.

Thanks again.  
Well though, I think NEST could have a better documentation, especially on the OIS format.

---

<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:** [February 9, 2018, 12:43am UTC](https://discuss.elastic.co/t/help-needed-on-nest-using-ois/118938/5 "2018-02-09T00:43:53Z")

</div>

Glad you got it sorted.

With regards to `"format"`, the parameter is used to tell Elasticsearch how to parse the date string in JSON into a Date object representation on the server side for Elasticsearch to work with.

By default, the client always sends `DateTime` and `DateTimeOffset` in ISO8601 format, using the default date serialization within [Json.NET](http://Json.NET), and ISO8601 format can be parsed by Elasticsearch using the default `"format"`, so it doesn't need to be specified. If you need to send any other format however, you would need to do two things

1. tell Elasticsearch how it can parse a date from the string using the `"format"` parameter on the request

2. serialize the operator values of the query using that format. The [`DateRangeQuery`] ([Date Range Query Usage | Elasticsearch.Net and NEST: the .NET clients [5.x] | Elastic](https://www.elastic.co/guide/en/elasticsearch/client/net-api/5.x/date-range-query-usage.html)) accepts [`DateMath`](https://www.elastic.co/guide/en/elasticsearch/client/net-api/5.x/date-math-expressions.html) for the operator values (`GreaterThan`, etc.) and there are implicit conversions from `string` and `DateTime` to `DateMath`, but with the latter, you cannot control the serialization of `DateTime` inside of `DateMath`. So in order to work with a `"format"`, you need to pass a string for `DateMath` as you have done.

> [@Joey\_Lu](#):
>
> Well though, I think NEST could have a better documentation, especially on the OIS format.

Always keen to hear feedback on the documentation. Which particular areas do you feel we are missing?

---

<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:** [March 9, 2018, 12:44am UTC](https://discuss.elastic.co/t/help-needed-on-nest-using-ois/118938/6 "2018-03-09T00:44:18Z")

</div>

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