This topic provides examples of index operations for common ES versions.
Sample data
This topic provides sample data and uses it to demonstrate the relevant operations.
{
"products": [
{
"productName": "Wealth Management Product A",
"annual_rate": "3.2200%",
"describe": "A 180-day fixed-term wealth management product. The minimum investment is 20,000. It provides stable returns and lets you choose whether to receive message pushes."
},
{
"productName": "Wealth Management Product B",
"annual_rate": "3.1100%",
"describe": "A 90-day regular investment product. The minimum investment is 10,000. A message is pushed every day when the earnings are credited to your account."
},
{
"productName": "Wealth Management Product C",
"annual_rate": "3.3500%",
"describe": "A 270-day regular investment product. The minimum investment is 40,000. A message is pushed every day when the earnings are immediately credited to your account."
},
{
"productName": "Wealth Management Product D",
"annual_rate": "3.1200%",
"describe": "A 90-day regular investment product. The minimum investment is 12,000. A message is pushed every day when the earnings are credited to your account."
},
{
"productName": "Wealth Management Product E",
"annual_rate": "3.0100%",
"describe": "A recommended 30-day regular investment product. The minimum investment is 8,000. A message about daily earnings is pushed."
},
{
"productName": "Wealth Management Product F",
"annual_rate": "2.7500%",
"describe": "A popular 3-day short-term product. No service fee is required. The minimum investment is 500. You can receive earnings messages by text message."
}
]
}Create an index
Create an index named product_info:
Versions 7.0 and later
PUT /product_info
{
"settings": {
"number_of_shards": 5,
"number_of_replicas": 1
},
"mappings": {
"properties": {
"productName": {
"type": "text",
"analyzer": "ik_smart"
},
"annual_rate":{
"type":"keyword"
},
"describe": {
"type": "text",
"analyzer": "ik_smart"
}
}
}
}Versions 7.0 and earlier
PUT /product_info
{
"settings": {
"number_of_shards": 5,
"number_of_replicas": 1
},
"mappings": {
"products": {
"properties": {
"productName": {
"type": "text",
"analyzer": "ik_smart"
},
"annual_rate":{
"type":"keyword"
},
"describe": {
"type": "text",
"analyzer": "ik_smart"
}
}
}
}
}In Elasticsearch 7.0 and later, the type definition is removed from mappings. Earlier versions continue to support the type definition. If you use a type in version 7.0 or later, the "type": "mapper_parsing_exception" fault message is returned. For more information, see Removal of mapping types.
After the index is created, the following result is returned.
{
"acknowledged" : true,
"shards_acknowledged" : true,
"index" : "product_info"
}Create a document and insert data
Version 8.x
POST /product_info/_bulk
{"index":{}}
{"productName":"Wealth Management Product A","annual_rate":"3.2200%","describe":"A 180-day fixed-term wealth management product. The minimum investment is 20,000. It provides stable returns and lets you choose whether to receive message pushes."}
{"index":{}}
{"productName":"Wealth Management Product B","annual_rate":"3.1100%","describe":"A 90-day regular investment product. The minimum investment is 10,000. A message is pushed every day when the earnings are credited to your account."}
{"index":{}}
{"productName":"Wealth Management Product C","annual_rate":"3.3500%","describe":"A 270-day regular investment product. The minimum investment is 40,000. A message is pushed every day when the earnings are immediately credited to your account."}
{"index":{}}
{"productName":"Wealth Management Product D","annual_rate":"3.1200%","describe":"A 90-day regular investment product. The minimum investment is 12,000. A message is pushed every day when the earnings are credited to your account."}
{"index":{}}
{"productName":"Wealth Management Product E","annual_rate":"3.0100%","describe":"A recommended 30-day regular investment product. The minimum investment is 8,000. A message about daily earnings is pushed."}
{"index":{}}
{"productName":"Wealth Management Product F","annual_rate":"2.7500%","describe":"A popular 3-day short-term product. No service fee is required. The minimum investment is 500. You can receive earnings messages by text message."}Version 7.x
POST /product_info/_doc/_bulk
{"index":{}}
{"productName":"Wealth Management Product A","annual_rate":"3.2200%","describe":"A 180-day fixed-term wealth management product. The minimum investment is 20,000. It provides stable returns and lets you choose whether to receive message pushes."}
{"index":{}}
{"productName":"Wealth Management Product B","annual_rate":"3.1100%","describe":"A 90-day regular investment product. The minimum investment is 10,000. A message is pushed every day when the earnings are credited to your account."}
{"index":{}}
{"productName":"Wealth Management Product C","annual_rate":"3.3500%","describe":"A 270-day regular investment product. The minimum investment is 40,000. A message is pushed every day when the earnings are immediately credited to your account."}
{"index":{}}
{"productName":"Wealth Management Product D","annual_rate":"3.1200%","describe":"A 90-day regular investment product. The minimum investment is 12,000. A message is pushed every day when the earnings are credited to your account."}
{"index":{}}
{"productName":"Wealth Management Product E","annual_rate":"3.0100%","describe":"A recommended 30-day regular investment product. The minimum investment is 8,000. A message about daily earnings is pushed."}
{"index":{}}
{"productName":"Wealth Management Product F","annual_rate":"2.7500%","describe":"A popular 3-day short-term product. No service fee is required. The minimum investment is 500. You can receive earnings messages by text message."}Version 7.10 supports the data insertion syntax for both ES 7.x and ES 8.x.
Versions earlier than 7.0
POST /product_info/products/_bulk
{"index":{}}
{"productName":"Wealth Management Product A","annual_rate":"3.2200%","describe":"A 180-day fixed-term wealth management product. The minimum investment is 20,000. It provides stable returns and lets you choose whether to receive message pushes."}
{"index":{}}
{"productName":"Wealth Management Product B","annual_rate":"3.1100%","describe":"A 90-day regular investment product. The minimum investment is 10,000. A message is pushed every day when the earnings are credited to your account."}
{"index":{}}
{"productName":"Wealth Management Product C","annual_rate":"3.3500%","describe":"A 270-day regular investment product. The minimum investment is 40,000. A message is pushed every day when the earnings are immediately credited to your account."}
{"index":{}}
{"productName":"Wealth Management Product D","annual_rate":"3.1200%","describe":"A 90-day regular investment product. The minimum investment is 12,000. A message is pushed every day when the earnings are credited to your account."}
{"index":{}}
{"productName":"Wealth Management Product E","annual_rate":"3.0100%","describe":"A recommended 30-day regular investment product. The minimum investment is 8,000. A message about daily earnings is pushed."}
{"index":{}}
{"productName":"Wealth Management Product F","annual_rate":"2.7500%","describe":"A popular 3-day short-term product. No service fee is required. The minimum investment is 500. You can receive earnings messages by text message."}The returned result contains "errors" : false, which indicates that the data was inserted successfully.
Search for data
Version 8.x
Full-text search
GET /product_info/_search { "query": { "match": { "describe": "A message is pushed every day when the earnings are credited to your account." } } }The following result is returned for a successful search:
{ "took": 15, "timed_out": false, "_shards": { "total": 5, "successful": 5, "skipped": 0, "failed": 0 }, "hits": { "total": { "value": 6, "relation": "eq" }, "max_score": 2.41246, "hits": [ { "_index": "product_info", "_id": "pgAGQZgB5J6iFDPOX2QN", "_score": 2.41246, "_source": { "productName": "Wealth Management Product B", "annual_rate": "3.1100%", "describe": "A 90-day regular investment product. The minimum investment is 10,000. A message is pushed every day when the earnings are credited to your account." } }, { "_index": "product_info", "_id": "pwAGQZgB5J6iFDPOX2QN", "_score": 2.343423, "_source": { "productName": "Wealth Management Product C", "annual_rate": "3.3500%", "describe": "A 270-day regular investment product. The minimum investment is 40,000. A message is pushed every day when the earnings are immediately credited to your account." } }, { "_index": "product_info", "_id": "qAAGQZgB5J6iFDPOX2QN", "_score": 1.7260926, "_source": { "productName": "Wealth Management Product D", "annual_rate": "3.1200%", "describe": "A 90-day regular investment product. The minimum investment is 12,000. A message is pushed every day when the earnings are credited to your account." } }, { "_index": "product_info", "_id": "qQAGQZgB5J6iFDPOX2QN", "_score": 0.9649055, "_source": { "productName": "Wealth Management Product E", "annual_rate": "3.0100%", "describe": "A recommended 30-day regular investment product. The minimum investment is 8,000. A message about daily earnings is pushed." } }, { "_index": "product_info", "_id": "pQAGQZgB5J6iFDPOX2QN", "_score": 0.8630463, "_source": { "productName": "Wealth Management Product A", "annual_rate": "3.2200%", "describe": "A 180-day fixed-term wealth management product. The minimum investment is 20,000. It provides stable returns and lets you choose whether to receive message pushes." } }, { "_index": "product_info", "_id": "qgAGQZgB5J6iFDPOX2QN", "_score": 0.19178316, "_source": { "productName": "Wealth Management Product F", "annual_rate": "2.7500%", "describe": "A popular 3-day short-term product. No service fee is required. The minimum investment is 500. You can receive earnings messages by text message." } } ] } }Search by query condition
Search for products with an annual rate between 3.0000% and 3.1300%.
GET /product_info/_search { "query": { "range": { "annual_rate": { "gte": "3.0000%", "lte": "3.1300%" } } } }The following result is returned for a successful search:
{ "took": 14, "timed_out": false, "_shards": { "total": 5, "successful": 5, "skipped": 0, "failed": 0 }, "hits": { "total": { "value": 3, "relation": "eq" }, "max_score": 1, "hits": [ { "_index": "product_info", "_id": "qAAGQZgB5J6iFDPOX2QN", "_score": 1, "_source": { "productName": "Wealth Management Product D", "annual_rate": "3.1200%", "describe": "A 90-day regular investment product. The minimum investment is 12,000. A message is pushed every day when the earnings are credited to your account." } }, { "_index": "product_info", "_id": "pgAGQZgB5J6iFDPOX2QN", "_score": 1, "_source": { "productName": "Wealth Management Product B", "annual_rate": "3.1100%", "describe": "A 90-day regular investment product. The minimum investment is 10,000. A message is pushed every day when the earnings are credited to your account." } }, { "_index": "product_info", "_id": "qQAGQZgB5J6iFDPOX2QN", "_score": 1, "_source": { "productName": "Wealth Management Product E", "annual_rate": "3.0100%", "describe": "A recommended 30-day regular investment product. The minimum investment is 8,000. A message about daily earnings is pushed." } } ] } }
For more information about search methods, see Query DSL.
Version 7.x
Full-text search
GET /product_info/_doc/_search { "query": { "match": { "describe": "A message is pushed every day when the earnings are credited to your account." } } }The following result is returned for a successful search:
{ "took" : 19, "timed_out" : false, "_shards" : { "total" : 5, "successful" : 5, "skipped" : 0, "failed" : 0 }, "hits" : { "total" : { "value" : 3, "relation" : "eq" }, "max_score" : 1.0, "hits" : [ { "_index" : "product_info", "_type" : "_doc", "_id" : "gC9RUJgBDC_Ir7OTV2QD", "_score" : 1.0, "_source" : { "productName" : "Wealth Management Product D", "annual_rate" : "3.1200%", "describe" : "A 90-day regular investment product. The minimum investment is 12,000. A message is pushed every day when the earnings are credited to your account." } }, { "_index" : "product_info", "_type" : "_doc", "_id" : "fi9RUJgBDC_Ir7OTV2QD", "_score" : 1.0, "_source" : { "productName" : "Wealth Management Product B", "annual_rate" : "3.1100%", "describe" : "A 90-day regular investment product. The minimum investment is 10,000. A message is pushed every day when the earnings are credited to your account." } }, { "_index" : "product_info", "_type" : "_doc", "_id" : "gS9RUJgBDC_Ir7OTV2QD", "_score" : 1.0, "_source" : { "productName" : "Wealth Management Product E", "annual_rate" : "3.0100%", "describe" : "A recommended 30-day regular investment product. The minimum investment is 8,000. A message about daily earnings is pushed." } } ] } }Search by query condition
Search for products with an annual rate between 3.0000% and 3.1300%.
GET /product_info/_doc/_search { "query": { "range": { "annual_rate": { "gte": "3.0000%", "lte": "3.1300%" } } } }The following result is returned for a successful search:
{ "took" : 5, "timed_out" : false, "_shards" : { "total" : 5, "successful" : 5, "skipped" : 0, "failed" : 0 }, "hits" : { "total" : { "value" : 3, "relation" : "eq" }, "max_score" : 1.0, "hits" : [ { "_index" : "product_info", "_type" : "_doc", "_id" : "gC9RUJgBDC_Ir7OTV2QD", "_score" : 1.0, "_source" : { "productName" : "Wealth Management Product D", "annual_rate" : "3.1200%", "describe" : "A 90-day regular investment product. The minimum investment is 12,000. A message is pushed every day when the earnings are credited to your account." } }, { "_index" : "product_info", "_type" : "_doc", "_id" : "fi9RUJgBDC_Ir7OTV2QD", "_score" : 1.0, "_source" : { "productName" : "Wealth Management Product B", "annual_rate" : "3.1100%", "describe" : "A 90-day regular investment product. The minimum investment is 10,000. A message is pushed every day when the earnings are credited to your account." } }, { "_index" : "product_info", "_type" : "_doc", "_id" : "gS9RUJgBDC_Ir7OTV2QD", "_score" : 1.0, "_source" : { "productName" : "Wealth Management Product E", "annual_rate" : "3.0100%", "describe" : "A recommended 30-day regular investment product. The minimum investment is 8,000. A message about daily earnings is pushed." } } ] } }
Version 7.10 supports the data query syntax for both ES 7.x and ES 8.x.
For more information about search methods, see Query DSL.
Versions earlier than 7.0
Full-text search
GET /product_info/products/_search { "query": { "match": { "describe": "A message is pushed every day when the earnings are credited to your account." } } }The following result is returned for a successful search:
{ "took" : 21, "timed_out" : false, "_shards" : { "total" : 5, "successful" : 5, "skipped" : 0, "failed" : 0 }, "hits" : { "total" : 6, "max_score" : 2.6264062, "hits" : [ { "_index" : "product_info", "_type" : "products", "_id" : "J8YIQZgBMhABkprCeWXb", "_score" : 2.6264062, "_source" : { "productName" : "Wealth Management Product B", "annual_rate" : "3.1100%", "describe" : "A 90-day regular investment product. The minimum investment is 10,000. A message is pushed every day when the earnings are credited to your account." } }, { "_index" : "product_info", "_type" : "products", "_id" : "KcYIQZgBMhABkprCeWXb", "_score" : 1.489365, "_source" : { "productName" : "Wealth Management Product D", "annual_rate" : "3.1200%", "describe" : "A 90-day regular investment product. The minimum investment is 12,000. A message is pushed every day when the earnings are credited to your account." } }, { "_index" : "product_info", "_type" : "products", "_id" : "KMYIQZgBMhABkprCeWXb", "_score" : 1.4445845, "_source" : { "productName" : "Wealth Management Product C", "annual_rate" : "3.3500%", "describe" : "A 270-day regular investment product. The minimum investment is 40,000. A message is pushed every day when the earnings are immediately credited to your account." } }, { "_index" : "product_info", "_type" : "products", "_id" : "K8YIQZgBMhABkprCeWXb", "_score" : 0.5753642, "_source" : { "productName" : "Wealth Management Product F", "annual_rate" : "2.7500%", "describe" : "A popular 3-day short-term product. No service fee is required. The minimum investment is 500. You can receive earnings messages by text message." } }, { "_index" : "product_info", "_type" : "products", "_id" : "JsYIQZgBMhABkprCeWXb", "_score" : 0.5469647, "_source" : { "productName" : "Wealth Management Product A", "annual_rate" : "3.2200%", "describe" : "A 180-day fixed-term wealth management product. The minimum investment is 20,000. It provides stable returns and lets you choose whether to receive message pushes." } }, { "_index" : "product_info", "_type" : "products", "_id" : "KsYIQZgBMhABkprCeWXb", "_score" : 0.53964466, "_source" : { "productName" : "Wealth Management Product E", "annual_rate" : "3.0100%", "describe" : "A recommended 30-day regular investment product. The minimum investment is 8,000. A message about daily earnings is pushed." } } ] } }Search by query condition
Search for products with an annual rate between 3.0000% and 3.1300%.
GET /product_info/products/_search { "query": { "range": { "annual_rate": { "gte": "3.0000%", "lte": "3.1300%" } } } }The following result is returned for a successful search:
{ "took" : 15, "timed_out" : false, "_shards" : { "total" : 5, "successful" : 5, "skipped" : 0, "failed" : 0 }, "hits" : { "total" : 3, "max_score" : 1.0, "hits" : [ { "_index" : "product_info", "_type" : "products", "_id" : "J8YIQZgBMhABkprCeWXb", "_score" : 1.0, "_source" : { "productName" : "Wealth Management Product B", "annual_rate" : "3.1100%", "describe" : "A 90-day regular investment product. The minimum investment is 10,000. A message is pushed every day when the earnings are credited to your account." } }, { "_index" : "product_info", "_type" : "products", "_id" : "KcYIQZgBMhABkprCeWXb", "_score" : 1.0, "_source" : { "productName" : "Wealth Management Product D", "annual_rate" : "3.1200%", "describe" : "A 90-day regular investment product. The minimum investment is 12,000. A message is pushed every day when the earnings are credited to your account." } }, { "_index" : "product_info", "_type" : "products", "_id" : "KsYIQZgBMhABkprCeWXb", "_score" : 1.0, "_source" : { "productName" : "Wealth Management Product E", "annual_rate" : "3.0100%", "describe" : "A recommended 30-day regular investment product. The minimum investment is 8,000. A message about daily earnings is pushed." } } ] } }
For more information about search methods, see Query DSL.
Delete an index
After you complete the examples, you can run the following command to delete the index to avoid wasting resources.
After an index is deleted, it cannot be recovered. Perform this operation with caution.
DELETE /product_infoAfter the index is deleted, the following result is returned.
{
"acknowledged" : true
}