This article is a mirror article of machine translation, please click here to jump to the original article.

View: 197688|Reply: 35

[Source] [Actual combat]. net/c# Call elasticsearch search via NEST [with source code]

[Copy link]
Posted on 12/20/2018 5:32:53 PM | | | |
ElasticSearch:

ES is a near-real-time search platform based on Lucene, which provides a distributed full-text search engine that uses RESTful as an API interface to index and query indexes and data through simple Get, Post and other operations.


Essential Knowledge:

Centos 7 installation and deployment elasticsearch-6.5.2 tutorial
https://www.itsvse.com/thread-6173-1-1.html
(Source: Architect_Programmer)
Install the elasticsearch-6.5.2 elasticsearch-head plugin
https://www.itsvse.com/thread-6190-1-1.html
(Source: Architect_Programmer)
Tutorial on installing elasticsearch-analysis-ik in elasticsearch-6.5.2
https://www.itsvse.com/thread-6191-1-1.html
(Source: Architect_Programmer)

Installation:

NEST can be installed using nuget with the following command:



.NET version requires at least 4.6, which is detailed as follows:The hyperlink login is visible.

Hi, we did drop .NET 4.5 support for .netstandard1.3, net46 is the new baseline.

We did this so that we could start introducing netcoreapp2.1 TFM and focus on bringing all the performance work to the client.

Can you tell us about your environment?

.NET 4.5 started in 2012 and by 2014 only 4.5.2 was supported by Microsoft. At some point, we need to make the difficult decision to abandon 4.5.2 so that we can focus more on the current and newer .NET versions. Just like we gave up a few years ago. NET 3.5, this is not an easy task.


Create an index:

If the index does not exist, use the following method to create a mapping at the same time as the index is created

Send a put request to the interface, and the json data is as follows:


Back:

{
"acknowledged": true,
"shards_acknowledged": true,
"index": "test1"
}

As shown below:



Add documentation:

In fact, it is to add data, which is equivalent to the rows of the database, I collected some 163 news and successfully added a total of 45 articles, as shown in the figure below:



Look at the added data via the elasticsearch-head plugin.



Manually add a piece of data with html code, put the content as follows:



We insert a piece of data with HTML tags to test the highlighting function, whether to escape the original html and js code, otherwise it will cause xss attacks, etc.

Search:

Search for keywords such as "man" and "test" through the software, and the correct search results will appear, and the request content of the post will be displayed, which is convenient for us to debug, as follows:



Search for test keywords and find that the html code contained in the record has been successfully escaped!

The source code contains the news txt file, Winform calls elasticsearch source code to download:

Tourists, if you want to see the hidden content of this post, pleaseReply





Previous:When I first came to the ramp, I shared the fashion design tutorial with everyone
Next:CodeIgniter, a simple and fast PHP MVC framework
 Landlord| Posted on 12/24/2018 11:03:23 AM |
Create index code with nest:
Model:

View the mapping mapping: http://ip:9200/test2/_mapping?pretty



Posted on 12/28/2021 10:10:50 AM |
Elasticsearch.Net.UnexpectedElasticsearchClientException: Unable to deserialize current JSON object (e.g. {"name":"value"}) to type 'System. Int64' because the type requires JSON base values (e.g., strings, numbers, booleans, nulls) to be properly deserialized. To resolve this error, you can change the JSON to a JSON base value (e.g., string, number, boolean, null) or change the deserialization type to make it normal. .NET types (e.g., not primitive types like integers, not collection types) (e.g. arrays or lists), can be deserialized from JSON objects. You can also add a JsonObjectAttribute to the type to force it to deserialize from a JSON object. Path "hits.total.value", line 1, position 113.


I had the same issue, and it seems that NEST 6.6.0 library is not compatible with Elasticsearch 7.0. I had to update NEST to 7.0.0 (alpha at this point).


Upgrading NEST solves this issue
Posted on 7/22/2019 3:20:56 PM |
1121695511 Posted on 2019-7-18 10:27
I charged as a member, but downloading it was still the same mistake as the previous newspaper. Ouch. It is also a query error

To correct it, the program can run, but it is caused by a different version from the elasticsearch download
Posted on 12/21/2018 8:45:31 AM |
Not bad~ For me, full-text search is a problem
Posted on 12/21/2018 12:09:32 PM |
Thank you for sharing, let's take a look
Posted on 5/12/2019 5:22:14 PM |
Thank you landlord. He is a good person
Posted on 5/12/2019 5:35:00 PM |
I can't get off. Hey. Points. Traffic. All kinds of wants
Posted on 5/28/2019 5:53:48 PM |
Thank you for sharing, learning!
Posted on 6/18/2019 6:12:40 PM |
Fortunately, you can try it.
Posted on 6/19/2019 5:28:18 PM |
A good person has a safe life
Posted on 6/19/2019 6:07:29 PM |
Thank you for sharing, let's take a look
Disclaimer:
All software, programming materials or articles published by Code Farmer Network are only for learning and research purposes; The above content shall not be used for commercial or illegal purposes, otherwise, users shall bear all consequences. The information on this site comes from the Internet, and copyright disputes have nothing to do with this site. You must completely delete the above content from your computer within 24 hours of downloading. If you like the program, please support genuine software, purchase registration, and get better genuine services. If there is any infringement, please contact us by email.

Mail To:help@itsvse.com