# Nest problem to select data out of database

**URL:** <https://discuss.elastic.co/t/nest-problem-to-select-data-out-of-database/145518>\
**Category:** Elasticsearch\
**Created:** [August 22, 2018, 8:38am UTC](https://discuss.elastic.co/t/nest-problem-to-select-data-out-of-database/145518 "2018-08-22T08:38:05Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![PDAxh](https://avatars.discourse-cdn.com/v4/letter/p/ba8739/32.png) [@PDAxh](https://discuss.elastic.co/u/PDAxh)\
**Post date:** [August 22, 2018, 8:38am UTC](https://discuss.elastic.co/t/nest-problem-to-select-data-out-of-database/145518/1 "2018-08-22T08:38:05Z")

</div>

Hi!  
Im pretty new to ES and got a little problem,

This one works as it should.

public void testCreateIndexBasedOnSelectedOrderId()  
{  
var pool = new SingleNodeConnectionPool(new Uri(uri));  
var settings = new ConnectionSettings(pool).DisableDirectStreaming();  
var client = new ElasticClient(settings);

```
        QueryContainer query = new TermQuery()
        {
            Field = "OrderId",
            Value = "1"
        };
        var searchRequest = new SearchRequest(index: "testindex")
        {
            Query = query
        };
        var searchResult = client.Search<TestLogs>(searchRequest);

        Console.WriteLine(searchResult);

        Console.WriteLine("searchResponse.Documents.Count: " + searchResult.Documents.Count());
        Console.WriteLine("Checking Fields Values: " + searchResult.Fields.Count());
        Console.WriteLine("Checking Hits Values: " + searchResult.Hits.Count());

    
        var orderIdArray = searchResult.Documents.ToArray();

        Console.WriteLine(orderIdArray[0]);
        var i = 0;

        foreach (var s in orderIdArray)
        {

            Console.WriteLine($"{i}: OrderId:" + s.OrderID + " Event: " + s.Event + " Time: " + s.TimeStamp);
            i++;
        }

        Assert.AreNotEqual(orderIdArray, null);
    }

```

But once i change the

```
QueryContainer query = new TermsQuery()
            {
                Field = "Event",
                Value = "CreateOrder" <--- is the event, can be compared to previous number 2 , 
           
        };
        var searchRequest = new SearchRequest(index: "testindex")
        {
            Query = query
        };
        var searchResult = client.Search<TestLogs>(searchRequest);

```

but this time it wont give some output at all

output is:

Test method ELK\_algorithmsTests.TestIndexCreation.testToMakeSameSelectionButWithSelectedEvent threw exception:  
System.IndexOutOfRangeException: Indexet låg utanför gränserna för matrisen.  
vid ELK\_algorithmsTests.TestIndexCreation.testToMakeSameSelectionButWithSelectedEvent() i

```
Valid NEST response built from a successful low level call on POST: /testindex/_search?typed_keys=true
searchResponse.Documents.Count: 0
Checking Fields Values: 0
Checking Hits Values: 0

```

My question is more.. what did i miss here? any suggestions?

---

<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:** [August 27, 2018, 12:49am UTC](https://discuss.elastic.co/t/nest-problem-to-select-data-out-of-database/145518/2 "2018-08-27T00:49:21Z")

</div>

**_Please format your code_** using `</>` icon as explained in [this guide](https://discuss.elastic.co/t/about-the-elasticsearch-category/21). It will make your post much more readable!

Or use markdown style like:

````
```c#
CODE HERE
```

````

This is the icon to use if you are not using markdown format:

 ![image](https://us1.discourse-cdn.com/elastic/original/3X/7/e/7e6e239431ec2d71cbf1beef741f2e93e7cc762c.jpg)

There's a live preview panel for exactly this reasons.

Lots of people read these forums, and many of them will simply skip over a post that is difficult to read, because it's just too large an investment of their time to try and follow a wall of badly formatted text.  
If your goal is to get an answer to your questions, it's in your interest to make it as easy to read and understand as possible.  
Please update your post.

Thanks!

* * *

The first thing that I would check is the mapping for the `Event` field: I suspect it is mapped as a `text` datatype, meaning the input at index time is analyzed i.e. if the JSON document to be indexed has `"CreateOrder"` as a value for `Event` field, this will undergo analysis, and the resulting tokens from analysis will be stored in the inverted index. If no specific configuration has been given, this will use the Standard Analyzer.

The `terms` query is a terms-level query that does not analyze the query input. This means that the input to the query is not analyzed, and will be passed verbatim to look for matches against the `Event` field. The problem here however, is that if the `Event` field has been analyzed at index time, the query input will be compared against the tokens produced by analysis. Amongst other things, the Standard Analyzer lowercases tokens, so a terms-level query input that contains casing won't match against an analyzed field that has lowercased tokens.

If you've simply gone with the default mappings with Elasticsearch, the `Event` field will have been mapped as a `multi_field`, meaning there will be a sub field called `Event.keyword` in the mapping that is mapped as a `keyword` datatype. The `keyword` data type does not undergo analysis so a `terms` query against this field will work.

---

<div class="post-metadata">

**Author:** ![PDAxh](https://avatars.discourse-cdn.com/v4/letter/p/ba8739/32.png) [@PDAxh](https://discuss.elastic.co/u/PDAxh)\
**Post date:** [August 30, 2018, 8:16am UTC](https://discuss.elastic.co/t/nest-problem-to-select-data-out-of-database/145518/3 "2018-08-30T08:16:49Z")

</div>

Hi  
Ive edited my post, so now it should look better.

But thans alot, i discovered that the problem was as you suspected the relation with upper and lower case.

Problem solved by using only lowerchar while search in index.

Tanks alot!

---

<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:** [September 27, 2018, 8:16am UTC](https://discuss.elastic.co/t/nest-problem-to-select-data-out-of-database/145518/4 "2018-09-27T08:16:53Z")

</div>

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