创建索引,添加文档
PUT /example_index
{
"mappings": {
"properties": {
"term": {"type": "text" },
"type": {"type": "keyword"}
}
}
}
PUT /_bulk
{"create": {"_index": "example_index", "_id": 1}}
{"term": "Flu Shot", "type": "procedure"}
{"create": {"_index": "example_index", "_id": 2}}
{"term": "Fluphenazine", "type": "drug"}
{"create": {"_index": "example_index", "_id": 3}}
{"term": "Flu Shot2", "type": "procedure"}
{"create": {"_index": "example_index", "_id": 4}}
{"term": "Fluphenazine2", "type": "drug"}
结果:
{
"took" : 2,
"timed_out" : false,
"_shards" : {
"total" : 1,
"successful" : 1,
"skipped" : 0,
"failed" : 0
},
"hits" : {
"total" : {
"value" : 4,
"relation" : "eq"
},
"max_score" : 2.0,
"hits" : [
{
"_index" : "example_index",
"_type" : "_doc",
"_id" : "1",
"_score" : 2.0,
"_source" : {
"term" : "Flu Shot",
"type" : "procedure"
}
},
{
"_index" : "example_index",
"_type" : "_doc",
"_id" : "3",
"_score" : 2.0,
"_source" : {
"term" : "Flu Shot2",
"type" : "procedure"
}
},
{
"_index" : "example_index",
"_type" : "_doc",
"_id" : "2",
"_score" : 1.0,
"_source" : {
"term" : "Fluphenazine",
"type" : "drug"
}
},
{
"_index" : "example_index",
"_type" : "_doc",
"_id" : "4",
"_score" : 1.0,
"_source" : {
"term" : "Fluphenazine2",
"type" : "drug"
}
}
]
}
}