Nest problem to select data out of database

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("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();

        var i = 0;

        foreach (var s in orderIdArray)

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

        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?

Please format your code using </> icon as explained in this guide. It will make your post much more readable!

Or use markdown style like:


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

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.


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.

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!

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