Query_string query returns unexpected results using dotnet core 2.1.1

Infrastructure:
Elasticsearch, Kibana 6.3 (Azure, Kubernetes, Docker Cluster)
Masters: 2, Clients: 3, Data: 2

NEST, Elasticsearch.NET 6.2 - netstandard2.1?
dotnet core 2.1.1

We are having issues with a simple object hierarchy for people. Example of data returned looks like this:

{
    "took": 5,
    "timed_out": false,
    "_shards": {
        "total": 5,
        "successful": 2,
        "skipped": 0,
        "failed": 0
    },
    "hits": {
        "total": 1,
        "max_score": 11.922418,
        "hits": [
            {
                "_index": "people",
                "_type": "_doc",
                "_id": "19E68F17-1098-4F75-AECC-8410117FFD45",
                "_score": 11.922418,
                "_source": {
                    "id": "19E68F17-1098-4F75-AECC-8410117FFD45",
                    "personType": "Student",
                    "uniqueId": "366V2QFU4",
                    "firstName": "Alexus",
                    "middleName": "Tyesha",
                    "lastName": "Walton",
                    "maidenName": "",
                    "suffix": "",
                    "gender": "Female",
                    "birthdate": "",
                    "birthCity": "",
                    "birthState": "",
                    "birthCountry": ""
                }
            }
        ]
    }
}

The query used to pull our data in Kibana, which returns just one result, returns 10 using NEST. No matter how I formulate the query it keeps returning 10 results when I'm expecting one:

GET /people/_doc/_search
{
  "query": {
    "query_string":{
      "query":"+uniqueId:366V2QFU4 +personType:Student"
    }
  }
}

C#:
SearchDescriptor sd = new SearchDescriptor();
sd.Query(q => q
.QueryString(qs => qs
.Query("+uniqueId:366V2QFU4 +personType:student")));

If I using just a browser and use the following URI I get what I expect.
https://dev-elasticsearch.ourdomain.net/_search?q=+uniqueId:366V2QFU4

Any ideas what I'm doing wrong?

There's a couple of things that I can see that may make a difference

  1. query in Kibana is "+uniqueId:366V2QFU4 +personType:Student" but the query in NEST is "+uniqueId:366V2QFU4 +personType:student" (lowercase s at start of student).

  2. The Kibana query is run against _doc types in people index. It's not clear from your example if this is also the case in NEST (could you make the NEST sample a code block please, so it retains generics).

The following will work

var pool = new SingleNodeConnectionPool(new Uri("https://dev-elasticsearch.tneducation.net"));

var settings = new ConnectionSettings(pool)
    .DefaultMappingFor<Person>(m => m
        .IndexName("people")
    )
    .DefaultTypeName("_doc");

var client = new ElasticClient(settings);

var searchResponse = client.Search<Person>(s => s
	.Query(q => q
		.QueryString(qs => qs
			.Query("+uniqueId:366V2QFU4 +personType:Student")
		)
	)
);

var documents = searchResponse.Documents;

public class Person
{
	public string Id { get; set; }
	public string PersonType { get; set; }
	public string UniqueId { get; set; }
	public string FirstName { get; set; }
	public string MiddleName { get; set; }
	public string LastName { get; set; }
	public string MaidenName { get; set; }
	public string Suffix { get; set; }
	public string Gender { get; set; }
	public string Birthdate { get; set; }
	public string BirthCity { get; set; }
	public string BirthState { get; set; }
	public string BirthCountry { get; set; }
}

I would also strongly recommend you put some form of authentication and access control in front of the cluster, even for dev/testing environments.

Thanks for the quick reply Russ. I made the necessary changes and I'm still getting 10 documents back instead of just the one.


    var response = await Client.SearchAsync<Person>(s => s
                        .Query(q => q
                            .QueryString(qs => qs
                                .Query("+personType:Student +uniqueId:366V2QFU4"))));

    var result = response.Documents;

The content of the Client Property which is in a base class for all of our repository classes.


    _pool = new SingleNodeConnectionPool(new Uri(ServiceUri));
    _settings = new ConnectionSettings(_pool)
        .DefaultMappingFor<TEntity>(m => m.IndexName(Index))
        .DefaultTypeName("_doc");

    _client = new ElasticClient(_settings);

All of our indexes comply with the recommendations of the 6.x version which recommends the _doc as the doc type name.

There has to be something different with how kibana is querying elastic and NEST is doing it.

Yes, the authentication piece is coming for the cluster, we are just now getting it up and running. I plan to take advantage of the xpack shortly.

Thanks,

Mike Langley

Ok, I finally figured out whats been causing my nightmare. I'm not sure why but the difference between http and https is crucial. Internally in my config file the uri started with http instead of https and as soon as I figured this out and changed it the query came back with just one value.

Glad you got to the bottom of it @Mike_Langley!

Seems like a strange side effect for this difference!

I'm not sure why that side effect happened either, I'm just glad we've been able to move on.

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