C# NEST elasticsearch source filtering returning null for most of the fields












0















I am new to Elasticsearch with .NET using NEST.
I am trying to execute a simple search to match all and interested with only few properties. I am not able to get the values for almost all the fields in the source. all shows as null value



The index already exists in elasticsearch.



I have a class representing the type.



public class DocType
{
public long CommunicationsDate { get; set; }
public string ControlNumber { get; set; }
public string Kind { get; set; }
public string PrimaryCommuncationsName { get; set; }
public float RiskScore { get; set; }
}


and my mapping is:



PUT relativity
{
"mappings": {
"doctype": {
"properties": {
"comms_date": {
"type": "date"
},
"control_number": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"kind": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"primary_comms_name": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"risk_score": {
"type": "float"
}
}
}
}
}


The following query returns Hits count correctly but the values are null except for the Kind property. Not sure what am i doing wrong here. Is this because the property names are different in c# class or something else?



    return await _connection.Get<ElasticClient>().SearchAsync<DocType>(s =>
{
var searchDescriptor = s.Index("relativity")
.Type("DocType")
.Size(100)
.Source(sf => sf
.Includes(i => i
.Fields(
f => f.ControlNumber,
f => f.PrimaryCommuncationsName,
f => f.RiskScore,
f => f.Kind,
f => f.CommunicationsDate
)
)
);

}









share|improve this question



























    0















    I am new to Elasticsearch with .NET using NEST.
    I am trying to execute a simple search to match all and interested with only few properties. I am not able to get the values for almost all the fields in the source. all shows as null value



    The index already exists in elasticsearch.



    I have a class representing the type.



    public class DocType
    {
    public long CommunicationsDate { get; set; }
    public string ControlNumber { get; set; }
    public string Kind { get; set; }
    public string PrimaryCommuncationsName { get; set; }
    public float RiskScore { get; set; }
    }


    and my mapping is:



    PUT relativity
    {
    "mappings": {
    "doctype": {
    "properties": {
    "comms_date": {
    "type": "date"
    },
    "control_number": {
    "type": "text",
    "fields": {
    "keyword": {
    "type": "keyword",
    "ignore_above": 256
    }
    }
    },
    "kind": {
    "type": "text",
    "fields": {
    "keyword": {
    "type": "keyword",
    "ignore_above": 256
    }
    }
    },
    "primary_comms_name": {
    "type": "text",
    "fields": {
    "keyword": {
    "type": "keyword",
    "ignore_above": 256
    }
    }
    },
    "risk_score": {
    "type": "float"
    }
    }
    }
    }
    }


    The following query returns Hits count correctly but the values are null except for the Kind property. Not sure what am i doing wrong here. Is this because the property names are different in c# class or something else?



        return await _connection.Get<ElasticClient>().SearchAsync<DocType>(s =>
    {
    var searchDescriptor = s.Index("relativity")
    .Type("DocType")
    .Size(100)
    .Source(sf => sf
    .Includes(i => i
    .Fields(
    f => f.ControlNumber,
    f => f.PrimaryCommuncationsName,
    f => f.RiskScore,
    f => f.Kind,
    f => f.CommunicationsDate
    )
    )
    );

    }









    share|improve this question

























      0












      0








      0








      I am new to Elasticsearch with .NET using NEST.
      I am trying to execute a simple search to match all and interested with only few properties. I am not able to get the values for almost all the fields in the source. all shows as null value



      The index already exists in elasticsearch.



      I have a class representing the type.



      public class DocType
      {
      public long CommunicationsDate { get; set; }
      public string ControlNumber { get; set; }
      public string Kind { get; set; }
      public string PrimaryCommuncationsName { get; set; }
      public float RiskScore { get; set; }
      }


      and my mapping is:



      PUT relativity
      {
      "mappings": {
      "doctype": {
      "properties": {
      "comms_date": {
      "type": "date"
      },
      "control_number": {
      "type": "text",
      "fields": {
      "keyword": {
      "type": "keyword",
      "ignore_above": 256
      }
      }
      },
      "kind": {
      "type": "text",
      "fields": {
      "keyword": {
      "type": "keyword",
      "ignore_above": 256
      }
      }
      },
      "primary_comms_name": {
      "type": "text",
      "fields": {
      "keyword": {
      "type": "keyword",
      "ignore_above": 256
      }
      }
      },
      "risk_score": {
      "type": "float"
      }
      }
      }
      }
      }


      The following query returns Hits count correctly but the values are null except for the Kind property. Not sure what am i doing wrong here. Is this because the property names are different in c# class or something else?



          return await _connection.Get<ElasticClient>().SearchAsync<DocType>(s =>
      {
      var searchDescriptor = s.Index("relativity")
      .Type("DocType")
      .Size(100)
      .Source(sf => sf
      .Includes(i => i
      .Fields(
      f => f.ControlNumber,
      f => f.PrimaryCommuncationsName,
      f => f.RiskScore,
      f => f.Kind,
      f => f.CommunicationsDate
      )
      )
      );

      }









      share|improve this question














      I am new to Elasticsearch with .NET using NEST.
      I am trying to execute a simple search to match all and interested with only few properties. I am not able to get the values for almost all the fields in the source. all shows as null value



      The index already exists in elasticsearch.



      I have a class representing the type.



      public class DocType
      {
      public long CommunicationsDate { get; set; }
      public string ControlNumber { get; set; }
      public string Kind { get; set; }
      public string PrimaryCommuncationsName { get; set; }
      public float RiskScore { get; set; }
      }


      and my mapping is:



      PUT relativity
      {
      "mappings": {
      "doctype": {
      "properties": {
      "comms_date": {
      "type": "date"
      },
      "control_number": {
      "type": "text",
      "fields": {
      "keyword": {
      "type": "keyword",
      "ignore_above": 256
      }
      }
      },
      "kind": {
      "type": "text",
      "fields": {
      "keyword": {
      "type": "keyword",
      "ignore_above": 256
      }
      }
      },
      "primary_comms_name": {
      "type": "text",
      "fields": {
      "keyword": {
      "type": "keyword",
      "ignore_above": 256
      }
      }
      },
      "risk_score": {
      "type": "float"
      }
      }
      }
      }
      }


      The following query returns Hits count correctly but the values are null except for the Kind property. Not sure what am i doing wrong here. Is this because the property names are different in c# class or something else?



          return await _connection.Get<ElasticClient>().SearchAsync<DocType>(s =>
      {
      var searchDescriptor = s.Index("relativity")
      .Type("DocType")
      .Size(100)
      .Source(sf => sf
      .Includes(i => i
      .Fields(
      f => f.ControlNumber,
      f => f.PrimaryCommuncationsName,
      f => f.RiskScore,
      f => f.Kind,
      f => f.CommunicationsDate
      )
      )
      );

      }






      c# elasticsearch nest






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 22 '18 at 9:42









      Mukil DeepthiMukil Deepthi

      1,30221857




      1,30221857
























          1 Answer
          1






          active

          oldest

          votes


















          1














          Property need to have the same name in order to nest to map it correctly with your es index.



          You can use attribute in your c# class file to change the mappings if you want to have different name on c# side.
          You can use fluent mapping too.



          https://www.elastic.co/guide/en/elasticsearch/client/net-api/current/attribute-mapping.html



          Hope it's help



          ++






          share|improve this answer























            Your Answer






            StackExchange.ifUsing("editor", function () {
            StackExchange.using("externalEditor", function () {
            StackExchange.using("snippets", function () {
            StackExchange.snippets.init();
            });
            });
            }, "code-snippets");

            StackExchange.ready(function() {
            var channelOptions = {
            tags: "".split(" "),
            id: "1"
            };
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function() {
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled) {
            StackExchange.using("snippets", function() {
            createEditor();
            });
            }
            else {
            createEditor();
            }
            });

            function createEditor() {
            StackExchange.prepareEditor({
            heartbeatType: 'answer',
            autoActivateHeartbeat: false,
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader: {
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            },
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            });


            }
            });














            draft saved

            draft discarded


















            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53427932%2fc-sharp-nest-elasticsearch-source-filtering-returning-null-for-most-of-the-field%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown

























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            1














            Property need to have the same name in order to nest to map it correctly with your es index.



            You can use attribute in your c# class file to change the mappings if you want to have different name on c# side.
            You can use fluent mapping too.



            https://www.elastic.co/guide/en/elasticsearch/client/net-api/current/attribute-mapping.html



            Hope it's help



            ++






            share|improve this answer




























              1














              Property need to have the same name in order to nest to map it correctly with your es index.



              You can use attribute in your c# class file to change the mappings if you want to have different name on c# side.
              You can use fluent mapping too.



              https://www.elastic.co/guide/en/elasticsearch/client/net-api/current/attribute-mapping.html



              Hope it's help



              ++






              share|improve this answer


























                1












                1








                1







                Property need to have the same name in order to nest to map it correctly with your es index.



                You can use attribute in your c# class file to change the mappings if you want to have different name on c# side.
                You can use fluent mapping too.



                https://www.elastic.co/guide/en/elasticsearch/client/net-api/current/attribute-mapping.html



                Hope it's help



                ++






                share|improve this answer













                Property need to have the same name in order to nest to map it correctly with your es index.



                You can use attribute in your c# class file to change the mappings if you want to have different name on c# side.
                You can use fluent mapping too.



                https://www.elastic.co/guide/en/elasticsearch/client/net-api/current/attribute-mapping.html



                Hope it's help



                ++







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Nov 22 '18 at 16:49









                LeBigCatLeBigCat

                46317




                46317
































                    draft saved

                    draft discarded




















































                    Thanks for contributing an answer to Stack Overflow!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid



                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.


                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function () {
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53427932%2fc-sharp-nest-elasticsearch-source-filtering-returning-null-for-most-of-the-field%23new-answer', 'question_page');
                    }
                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    MongoDB - Not Authorized To Execute Command

                    How to fix TextFormField cause rebuild widget in Flutter

                    Npm cannot find a required file even through it is in the searched directory