elasticsearch做搜索

2026-06-13 13:52:19 阅读:13 编辑

cd /opt mkdir elasticsearch cd elasticsearch mkdir data mkdir logs cd ../.. chown -R 1000:1000 elasticsearch

docker run -d --name elasticsearch \ -p 9200:9200 -p 9300:9300 \ -e "discovery.type=single-node" \ -e "xpack.security.enabled=false" \ -e "ES_JAVA_OPTS=-Xms1g -Xmx1g" \ -v //mnt/vdb1/elasticsearch/data:/usr/share/elasticsearch/data \ -v //mnt/vdb1/elasticsearch/logs:/usr/share/elasticsearch/logs \ docker.elastic.co/elasticsearch/elasticsearch:8.15.0

我字段为fulltext做模糊搜索,返回id

curl -X PUT "http://localhost:9200/products" -H "Content-Type: application/json" -d ' { "mappings": { "properties": { "fulltext": { "type": "text" }, "id": { "type": "long" } } } }'

2. ES API 是否响应

curl http://localhost:9200

curl -X GET "http://localhost:9200/_cluster/health?pretty"

curl -X POST "http://localhost:9200/products/_bulk" -H "Content-Type: application/json" -d ' {"index":{}} {"id": 12345, "fulltext": "180天定期理财,最低20000起投,收益稳定"} {"index":{}} {"id": 12346, "fulltext": "90天定投产品,每天收益到账消息推送"} {"index":{}} {"id": 12347, "fulltext": "热门短期产品,最低500起投,无须手续费用"} '