1、将测试数据新增tag字段
POST /forum/article/_bulk
{"update" : {"_id": "1"}}
{"doc": {"tag": ["java","hadoop"]}}
{"update" : {"_id": "2"}}
{"doc": {"tag": ["java"]}}
{"update" : {"_id": "3"}}
{"doc": {"tag": ["hadoop"]}}
{"update" : {"_id": "4"}}
{"doc": {"tag": ["java","elasticsearch"]}}
2、搜索tag含有Java的文章
POST /forum/article/_search
{
"query": {"constant_score": {
"filter": {"terms": {
"tag": [
"java"
]
}}
}}
}
结果:
{
"took" : 19,
"timed_out" : false,
"_shards" : {
"total" : 5,
"successful" : 5,
"skipped" : 0,
"failed" : 0
},
"hits" : {
"total" : 3,
"max_score" : 1.0,
"hits" : [
{
"_index" : "forum",
"_type" : "article",
"_id" : "2",
"_score" : 1.0,
"_source" : {
"articleId" : "XHEX-A-3422-#f234",
"userId" : 2,
"hidden" : false,
"postDate" : "2021-