0
votes

I'm struggling to compare two fields using Elastic Search Nest client for c#, can somebody help me to achieve this? For Example : I've two fields like FirstName & Name in my index, I want to compare these fields.

1
Try using the script query and supply a painless script. See here for painless examples elastic.co/guide/en/elasticsearch/painless/current/…sramalingam24
How do you want to compare them? Equality? Numerical comparison? String comparison? Something else? Would you be able to edit your question to provide some details for how you wish to compare?Russ Cam
Lets assume you've Index called people & there we've following fields 1.Name (which have full name) 2.First Name 2.Last Name 3.Middle Name 4.Email 5.Address Now I want to compare 1.)Name & 2.) Full Name through out the index, so how can I do in Nest(c#) ?(All are string type & I want to check Equality. Hope this will help youLalit Khanna

1 Answers

1
votes

You can make this kind of comparison with a Script query

var client = new ElasticClient();

var response = client.Search<Question>(s => s
    .Query(q => q
        .Script(sq => sq
            .Source("doc['name'].value == doc['fullName'].value")
        )
    )
);

This retrieves the values from doc values and makes the assumption that both fields are indexed as keyword fields; doc values are not supported with text fields.