欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

Elasticearch(用POSTMAN测试)

程序员文章站 2022-07-12 13:34:10
...

创建索引库

PUT/POST方式提交
http://localhost:9200/my_course

地址: http://localhost:9200/my_course

带上下方JSON数据

举例:用POSTMAN提交找到Body中的raw并以JSON数据提交

{
	"settings": {
		"index": {
			"number_of_shards": 1,
			"number_of_replicas": 0
		}
	}
}

提交成功后应返回以下JSON数据

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

设置映射

POST提交
http://localhost:9200/my_course/doc/_mapping

地址: http://localhost:9200/my_course/doc/_mapping

带上下方JSON数据

举例:用POSTMAN提交找到Body中的raw并以JSON数据提交

{
	"properties": {
		"description": {
			"type": "text",
			"analyzer": "ik_max_word", //是否用ik
			"search_analyzer": "ik_smart"
		},
		"name": {
			"type": "text",
			"analyzer": "ik_max_word",
			"search_analyzer": "ik_smart"
		},
		"pic": {
			"type": "text",
			"index": false
		},
		"price": {
			"type": "float"
		},
		"studymodel": {
			"type": "keyword"
		},
		"timestamp": {
			"type": "date",
			"format": "yyyy-MM-dd HH:mm:ss||yyyy-MM-dd"
		}
	}
}

提交成功后应返回以下数据

{
    "acknowledged": true
}

把数据写入索引库

POST提交
http://localhost:9200/my_course/doc/3

 http://localhost:9200/my_course/doc/3    注:后面跟的3是数据的id

带上下方JSON数据

举例:用POSTMAN提交找到Body中的raw并以JSON数据提交

{
"name": "java编程基础", 
"description": "java语言是世界第一编程语言,在软件开发领域使用人数最多。", 
"pic":"group1/M00/00/01/wKhlQFqO4MmAOP53AAAcwDwm6SU490.jpg", 
"studymodel": "201001" ,
"timestamp":"2020-01-28 18:28:58" 
} 

提交成功后应返回以下数据

{
    "_index": "my_course",
    "_type": "doc",
    "_id": "3",  //这里的id就是上面地址跟的参数id
    "_version": 1,
    "result": "created",
    "_shards": {
        "total": 1,    
        "successful": 1, //成功
        "failed": 0
    },
    "_seq_no": 2,
    "_primary_term": 1
}

查询

GET提交
http://localhost:9200/my_course/doc/_search?q=name:java

 http://localhost:9200/my_course/doc/_search?q=name:java
   注:q=是固定语法,而name是根据name去查,如果改成description就意思是根据description去查询
   :后面跟的是查询内容	

查询成功应返回以下数据

{
    "took": 4,
    "timed_out": false,
    "_shards": {
        "total": 1,
        "successful": 1,
        "skipped": 0,
        "failed": 0
    },
    "hits": {
        "total": 1,
        "max_score": 0.9331132,
        "hits": [
            {
                "_index": "my_course",
                "_type": "doc",
                "_id": "3",
                "_score": 0.9331132,
                "_source": {
                    "name": "java编程基础",
                    "description": "java语言是世界第一编程语言,在软件开发领域使用人数最多。",
                    "pic": "group1/M00/00/01/wKhlQFqO4MmAOP53AAAcwDwm6SU490.jpg",
                    "studymodel": "201001",
                    "timestamp": "2020-01-28 18:28:58"
                }
            }
        ]
    }
}

删除

DELETE提交
http://localhost:9200/my_course

 http://localhost:9200/my_course  删除索引库

提交成功后应返回以下数据、

{
    "acknowledged": true
}
相关标签: elasticsearch