Пример #1
0
        public static bool insertDocument(string searchID, string tbxfirstname, string tbxLastname, string tbxcity)
        {
            bool status;

            var myJson = new
            {
                firstname = tbxfirstname,
                lastname  = tbxLastname,
                city      = tbxcity,
            };

            var response = ConnectionToES.EsClient().Index(myJson, i => i
                                                           .Index("accounts3")
                                                           .Type("account3")
                                                           .Id(searchID)
                                                           //.Refresh()
                                                           );

            if (response.IsValid)
            {
                status = true;
            }
            else
            {
                status = false;
            }
            getAllDocument();

            return(status);
        }
Пример #2
0
        ///Updating a Document can be done in trhee way
        ///1. Update by Partial Document
        ///2. Update by Index Query
        ///3. Update by Script
        ///Here we demonstrated Update by Partial Document and  Update by Index Query. User can choose any of these from below.
        ///Just comment one part and uncomment another.

        public static bool updateDocument(string searchID, string tbxfirstname, string tbxLastname, string tbxcity)
        {
            bool status;

            //Update by Partial Document
            var response = ConnectionToES.EsClient().Update <DocumentAttributes, UpdateDocumentAttributes>(searchID, d => d
                                                                                                           .Index("accounts3")
                                                                                                           .Type("account3")
                                                                                                           .Doc(new UpdateDocumentAttributes
            {
                firstname = tbxfirstname,
                lastname  = tbxLastname,
                city      = tbxcity,
            }));


            if (response.IsValid)
            {
                status = true;
            }
            else
            {
                status = false;
            }
            getAllDocument();

            return(status);
        }
Пример #3
0
        public static bool deleteDocument(string searchID)
        {
            bool status;

            var response = ConnectionToES.EsClient().Delete <DocumentAttributes>(searchID, d => d
                                                                                 .Index("accounts3")
                                                                                 .Type("account3"));

            if (response.IsValid)
            {
                status = true;
            }
            else
            {
                status = false;
            }
            getAllDocument();
            return(status);
        }
Пример #4
0
        public static DataTable getAllDocument()
        {
            DataTable dataTable = new DataTable("character");

            dataTable.Columns.Add("account_number", typeof(string));
            dataTable.Columns.Add("firstname", typeof(string));
            dataTable.Columns.Add("lastname", typeof(string));
            dataTable.Columns.Add("age", typeof(string));

            var response = ConnectionToES.EsClient().Search <DocumentAttributes>(s => s
                                                                                 .Index("accounts3")
                                                                                 .Type("account3")
                                                                                 .From(0)
                                                                                 .Size(1000)
                                                                                 .Query(q => q.MatchAll()));

            foreach (var hit in response.Hits)
            {
                dataTable.Rows.Add(hit.Id.ToString(), hit.Source.firstname.ToString(), hit.Source.lastname.ToString(), hit.Source.city.ToString());
            }

            return(dataTable);
        }
Пример #5
0
        public static Tuple <string, string, string, string> getDocument(string searchID)
        {
            string id        = "";
            string firstname = "";
            string lastname  = "";
            string city      = "";

            var response = ConnectionToES.EsClient().Search <DocumentAttributes>(s => s
                                                                                 .Index("accounts3")
                                                                                 .Type("account3")
                                                                                 .Query(q => q.Term(t => t.Field("_id").Value(searchID)))); //Search based in _id

            //Assigining value to their controller
            foreach (var hit in response.Hits)
            {
                id        = hit.Id.ToString();// Source.id.ToString();
                firstname = hit.Source.firstname.ToString();
                lastname  = hit.Source.lastname.ToString();
                city      = hit.Source.city.ToString();
            }

            return(Tuple.Create(id, firstname, lastname, city));
        }