Basic operation of Elastic search API
Article directory
1. Corresponding relationship with relational database
Relational database | Elasticsearch |
---|---|
Database | Index Library |
Table Table | Type Type |
Data row Row | Document |
Data Column | Field Field |
Model Schema | Image Mapping |
ES Restful API GET, POST, PUT, DELETE, HEAD Meaning:
1) GET: Gets the current state of the requesting object.
2) POST: Change the current state of the object.
3) PUT: Create an object.
4) DELETE: Destroy the object.
5) HEAD: Request the basic information of the object.
2. Index
Equivalent to a database
Create index
http://localhost:9200/{index} PUT http://localhost:9200/hello
Delete index
http://localhost:9200/{index} DELETE http://localhost:9200/hello
3,mapping
Create index and mapping
http://localhost:9200/{index} put: http://localhost:9200/hello2 { "mappings": { "article": { "properties": { "id": { "type": "long", "store": true, "index":"true" }, "title": { "type": "text", "store": true, "index":"true", "analyzer":"standard" }, "content": { "type": "text", "store": true, "index":"true", "analyzer":"standard" } } } } }
Set Mapping after Index Creation
http://localhost:9200/{index}/{type}/_mapping POST http://localhost:9200/hello/type_test/_mapping { "hello": { "properties": { "id":{ "type":"long", "store":true }, "title":{ "type":"text", "store":true, "index":true, "analyzer":"standard" }, "content":{ "type":"text", "store":true, "index":true, "analyzer":"standard" } } } }
4, document
http://localhost:9200/{index}/{type}/{_id}
4.1 New Documents
http://localhost:9200/{index}/{type}/{_id} post Can not be set_id.es Automatically generated, not recommended put/post http://localhost:9200/hello/article/1 { "id":1, "title":"ElasticSearch It is based on Lucene Search Server", "content":"It provides a full-text search engine based on distributed multi-user capabilities. RESTful web Interface. Elasticsearch Is used Java Developed and acted as Apache Open source publishing under licensing terms is a popular enterprise search engine. Design for cloud computing, can achieve real-time search, stable, reliable, fast, easy to install and use." }
4.2 Modify document
http://localhost:9200/{index}/{type}/{_id} POST localhost:9200/blog1/article/1 //Request body: { "id":1, "title":"[Amendment] ElasticSearch It is based on Lucene Search Server", "content":"[It provides a full-text search engine with distributed multi-user capabilities, based on RESTful web Interface. Elasticsearch Is used Java Developed and acted as Apache Open source publishing under licensing terms is a popular enterprise search engine. Design for cloud computing, can achieve real-time search, stable, reliable, fast, easy to install and use." }
4.3 Delete document
http://localhost:9200/{index}/{type}/{_id} DELETE localhost:9200/blog1/article/1
4.4 Document Query
4.4.1 Find by id
http://localhost:9200/{index}/{type}/{_id} GET localhost:9200/blog1/article/1
4.4.2 querystring query
First participle, then query, including participle will be queried out
POST localhost:9200/blog1/article/_search { "query": { "query_string": { "default_field": "title", "query": "Search Server" } } }
4.4.2 term query
Represents a perfect match, that is, without word segmentation, the document must contain the entire search term
POST localhost:9200/blog1/article/_search { "query": { "term": { "title": "search" } } }