. Net Elasticsearch getting started,. netelasticsearch

Source: Internet
Author: User
Tags solr

. Net Elasticsearch getting started,. netelasticsearch

1. es Installation
1. elasticsearch Installation
Run http: // localhost: 9200/
2. head plug-in
3. Install the bigdesk plug-in
(Installation Details: windows elasticsearch installation, details)

Ii. es plug-ins
Http://www.searchtech.pro/elasticsearch-plugins (es plug-in Daquan)
Https://github.com/medcl/elasticsearch-analysis-ik (ik Project)
Https://github.com/lmenezes/elasticsearch-kopf (elasticsearch plug-ins MONITOR node status, you can also debug your elasticsearch)
Https://github.com/medcl/elasticsearch-rtf/tree/master (2.1.1 + 1.6ik is integrated with Pinyin and other word divider)
Https://github.com/lmenezes/elasticsearch-kopf (head-like plug-in)
Https://www.elastic.co/downloads/marvel (Monitoring ES health status)
Konf plug-in (it is said that the Cluster load can be viewed)

Iii. es C # client example

1. Download The elasticsearch.net and nest components in the package.
The nest component depends on the elasticsearch component.
Documentation: http://nest.azurewebsites.net/
Note:. net uses fewer elasticsearch instances and the elasticsearch version is updated quickly. Many elasticsearch instances use elasticsearch on their own. Multi-communication and multi-sharing.
2. Create a Connection Client
Public ElasticClient GetClient ()
{
Var node = new Uri ("http: // 192.168.17.54: 9200 ");

Var settings = new ConnectionSettings (
Node,
DefaultIndex: "my-application"

);
Return new ElasticClient (settings );
}
3. Create an index model (index structure)
[ElasticType (IdProperty = "Id", Name = "Person")]
Public class Person
{
[ElasticProperty (Name = "Id", Type = FieldType. String, Index = FieldIndexOption. NotAnalyzed)]
Public string Id {get; set ;}
Public string Firstname {get; set ;}
Public string Lastname {get; set ;}
Public string [] Chains {get; set ;}
[ElasticProperty (Name = "content", Type = FieldType. String, Index = FieldIndexOption. Analyzed, Analyzer = "ik_max_word")]
Public string Content {get; set ;}
}
Note: For more details about the model example provided by others, you can download the attachment.
4. Index content (create index)
Private void btnIndex_Click (object sender, EventArgs e)
{
// Var client = new ElasticsearchClient ();
/// Index a document under/myindex/mytype/1
// Var indexResponse = client. Index ("myindex", "mytype", "1", new {Hello = "World "});
Var client2 = GetClient ();

// Client2.CreateIndex ("test ");
// Client2.Map <Person> (c => c. MapFromAttributes ());

IEnumerable <Person> persons = new List <Person>
{
New Person ()
{
Id = "4 ",
Firstname = "aaa", // Boterhuis-040
Lastname = "Gusto-040 ",
Chains = new string [] {"a", "B", "c "},
},
New Person ()
{
Id = "5 ",
Firstname = "sales@historichousehotels.com ",
Lastname = "t Boterhuis 1 ",
Chains = new string [] {"a", "B", "c "},
},
New Person ()
{
Id = "6 ",
Firstname = "Aberdeen #110 ",
Lastname = "sales@historichousehotels.com ",
Chains = new string [] {"a", "B", "c "},
},
New Person ()
{
Id = "7 ",
Firstname = "Aberdeen #110 ",
Lastname = "t Boterhuis 2 ",
Chains = new string [] {"a", "B", "c "},
},
New Person ()
{
Id = "8 ",
Firstname = "Aberdeen #110 ",
Lastname = "t Boterhuis 2 ",
Chains = new string [] {"a", "B", "c "},
},
};
// Foreach (var p in persons)
Client2.indexusers <Person> (persons, "test ");
}
5. Simple search example
Var client = GetClient ();
Var rs = client. Search <Person> (s => s. Index ("test"). QueryString (this. textBox1.Text ));
This. richTextBox1.Text = JsonConvert. SerializeObject (rs. events );
6. Index Update
Private void btnUpdate_Click (object sender, EventArgs e)
{
Var client2 = GetClient ();

Client2.Update <Person, object> (u => u
. Index ("test ")
. Id (4)
. Doc (new {Id = "4", Firstname = "United States "})
. RetryOnConflict (3)
. Refresh ()
);

// Var u1 = new Person ()
//{
// Id = "4 ",
// Firstname = "Boterhuis-040 ",
// Lastname = "Gusto-040 ",
// Chains = new string [] {"a", "B", "c "},
//};
// Var u2 = new Person ()
//{
// Id = "4 ",
// Firstname = "United States ",
// Lastname = "Gusto-040 ",
// Chains = new string [] {"a", "B", "c "},
//};
// Client2.Update <Person, Person> (u1, u2 ).
}

7. Index Deletion
Private void btnDelete_Click (object sender, EventArgs e)
{
Var client2 = GetClient ();
Client2.DeleteIndex ("test ");
Client2.DeleteIndex ("my-application ");
}
8. Summary
The above sample code is sufficient for simple applications. Others are highlighted and grouped. You can see the document.

Iv. es Cluster
Elasticsearch is a cluster by default, which is easier to configure and build than solr cloud. However, it takes a lot of time and effort to design your own clusters based on your business needs. (Easy to use, easy to use)

V. Comparison between es and solr
What I know currently:
It turns out that solr has a lot of data, and now it seems that elasticsearch has more data. Solr is an official pdf in English, and es is also in English.
It turns out that solr still has Chinese books, and now it seems there is no more. Elasticsearch currently has several books, but the elasticsearch version is somewhat outdated.
Solr is a little difficult to get started with es.
(I used solr n years ago. At that time, solrcloud was not available; es was not yet available. At that time, there were more solr materials. I have also implemented my own solr cluster solution. The comparison of other functions is still Baidu, which is not repeated .)

6. If the es client debugs the request
We recommend that you download tcp interception tools such as HTTPAnalyzer. In this way, you can intercept the request connection from the verification sdk, and compare the materials and books to see which parameters are wrong, which is very helpful for debugging.

VII. es Appendix
Elasticsearch terms:
Cluster:

A cluster contains multiple nodes, one of which is the master node. This master node can be elected. Note that the master and slave nodes are used within the cluster. One concept of es is decentralization. Literally, it is a non-central node. This is for the outside of the cluster, because the elasticsearch cluster is logically a whole, communication between you and any node is equivalent to communication with the entire elasticsearch cluster.
Shards

Indicates the index partition. Elasticsearch divides a complete index into Multiple shards. This way, you can split a large index into Multiple shards and distribute them to different nodes. Create a distributed search. The number of shards can only be specified before the index is created and cannot be changed after the index is created.
Replicas

Represents the index copy. elasticsearch can set multiple index copies. Replica improves system fault tolerance. When a shard of a node is damaged or lost, it can be recovered from the replica. Second, it improves the query efficiency of es, elasticsearch automatically performs load balancing on search requests.
Recovery

This indicates data recovery or data redistribution. When a node is added or exited, elasticsearch redistributes the index shards Based on the server load. When the node is restarted, the data is also restored.
River

It represents a data source of es and is also a method for synchronizing data from other storage methods (such as databases) to es. It is an es service that exists as a plug-in. It reads data from the river and indexes it into es. The official river has couchDB, RabbitMQ, Twitter, and Wikipedia.
Gateway

Represents the storage method of elasticsearch index snapshots. Elasticsearch stores indexes in the memory by default. When the memory is full, the indexes are persisted to the local hard disk. Gateway stores index snapshots. When the elasticsearch cluster is closed and then restarted, it reads the index backup data from the gateway. Elasticsearch supports multiple types of gateways, including local file systems (default), distributed file systems, Hadoop HDFS, and amazon s3 cloud storage services.
Discovery. zen

This indicates the automatic discovery node mechanism of es. Es is a p2p-based system. It first searches for existing nodes through broadcast, then communicates between nodes through multicast protocol, and also supports point-to-point interaction.
Transport

Represents the interaction between an elasticsearch node or cluster and the client. By default, tcp is used internally for interaction, and it supports transmission protocols such as http (json format), thrift, servlet, memcached, and zeroMQ (integration through plug-ins ).

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.