. NET Elasticsearch Learn Getting Started notes

Source: Internet
Author: User
Tags solr

I. ES installation-related
1.elasticsearch Installation
Run Http://localhost:9200/
2.head Plug-in
3.bigdesk Plug-in installation
(Installation details Baidu: Windows Elasticsearch installation, detailed content)

Two. Es plugin-related
Http://www.searchtech.pro/elasticsearch-plugins (es plugin Daquan)
Https://github.com/medcl/elasticsearch-analysis-ik (IK project)
Https://github.com/lmenezes/elasticsearch-kopf (es plug-in monitoring node status, you can also debug your ES query)
Https://github.com/medcl/elasticsearch-rtf/tree/master (2.1.1 + 1.6ik with pinyin and other word breakers integrated)
Https://github.com/lmenezes/elasticsearch-kopf (head-like plug-in)
Https://www.elastic.co/downloads/marvel (monitor ES health status)
Konf plug-in (said to look at cluster load)

three. ES C # Client Sample

1. Package download Elasticsearch.net,nest components.
The nest component relies on downloading the Elasticsearch component.
Working with Documents: http://nest.azurewebsites.net/
NOTE:. NET uses a relatively small number of ES, ES version updates are also very fast, many use also rely on their own. More communication, more 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: The model example provided by others, in more detail, can be downloaded as an 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 = "[email protected]",
Lastname = "T Boterhuis 1",
Chains = new string[]{"A", "B", "C"},
},
New Person ()
{
Id = "6",
Firstname = "Aberdeen #110",
Lastname = "[email protected]",
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. indexmany<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. Documents);
6. Index Updates
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 = "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 = "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
In the example code above, a simple application is sufficient. The others are highlighting and grouping. You can see the document.

four. ES cluster
ES is a cluster by default, simpler to configure than SOLR cloud, and easier to build. But more still have to be based on the business of their own cluster design or good time, a lot of energy. (Easy to get started, hard to use)

five. Es vs. SOLR
What the individual currently understands:
The original SOLR more information, now looks like es more information. SOLR is the official English pdf,es also in English.
The original SOLR also has Chinese books, now seems to have no. ES currently has several books, but the ES version is slightly older.
SOLR is slightly more difficult to get started with ES.
(N years ago, I used the SOLR, when there is no solrcloud;es yet out, then SOLR data more.) Individuals have also implemented their own SOLR cluster solution. Other features on the contrast, or Baidu, do not repeat. )

Six. If the ES client debug request
We recommend that you download a TCP interception tool such as Httpanalyzer. This can intercept the verification SDK out of the request connection, compare the data and books to see which parameters are wrong, debugging is very helpful.

Seven. ES appendix
Es term Description:
Cluster

Represents a cluster in which there are multiple nodes, one of which is the primary node. This master node can be elected. Note that the master-slave node is for the inside of the cluster. One of the concepts of ES is to center, literally understand that there is no central node, this is for the outside of the cluster, because the ES cluster from the outside, in a logical whole, you communicate with any one node and the entire ES cluster communication is equivalent.
Shards

Represents the Index Shard. Es can divide a complete index into multiple shards, and the benefit is that a large index can be split into multiple nodes. constitute 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 a copy of an index, ES can set a copy of multiple indexes. The role of the replica, one is to improve the system's fault tolerance, when a node of a shard corruption or loss can be recovered from the replica, the second is to improve the efficiency of the query es, ES will automatically load balance search requests.
Recovery

Represents data recovery or redistribution of data, ES when a node joins or exits the index shards are redistributed based on the load of the machine, and data recovery occurs when the node is restarted.
River

Represents a data source for ES and is also a way to synchronize data to ES with other storage methods (such as databases). It is an ES service that exists in plug-in mode, by reading the data in the river and indexing it into ES, the official river is couchdb, RABBITMQ, Twitter, Wikipedia.
Gateway

Represents how the ES index snapshot is stored. ES defaults to storing the index in memory and then persisting to the local hard disk when the memory is full. The Gateway stores the index snapshot, and when the ES cluster is shut down and restarted, the index backup data is read from the gateway. ES supports multiple types of gateway, with local file system (default), Distributed File System, Hadoop HDFs and Amazon's S3 cloud storage service.
Discovery.zen

Represents the automatic discovery node mechanism for ES. ES is a peer-based system that first searches for existing nodes by broadcasting, and then communicates between nodes through multicast protocols, while also supporting point-to-point interactions.
Transport

Represents how es internal nodes or clusters interact with the client. The default internal is to use the TCP protocol to interact, while it supports the HTTP protocol (JSON format), thrift, servlet, memcached, ZEROMQ and other transport protocols (through plug-in mode integration).

. NET Elasticsearch Learn Getting Started notes

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.