admin管理员组

文章数量:1531375

世界上并没有完美的程序,但是我们并不因此而沮丧,因为写程序就是一个不断追求完美的过程。

问:significant_text有什么特点?
答:

问:significant_text如何使用?
答:

# 删除
DELETE /significant_text_test

# 映射
PUT /significant_text_test
{
  "mappings": {
    "properties": {
      "name": {"type": "text"},
      "filter_type": {"type": "keyword"}
    }
  }
}

# 索引
POST /significant_text_test/_bulk?routing=1&refresh
{"index": {"_id": 1}}
{"name": "hello good", "filter_type": "t1"}
{"index": {"_id": 2}}
{"name": "me good", "filter_type": "t2"}
{"index": {"_id": 3}}
{"name": "me hello", "filter_type": "t1"}
{"index": {"_id": 4}}
{"name": "server hello good me", "filter_type": "t1"}
{"index": {"_id": 5}}
{"name": "service me good hello", "filter_type": "t1"}
{"index": {"_id": 6}}
{"name": "redis hello good", "filter_type": "t2"}
{"index": {"_id": 7}}
{"name": "redis good me", "filter_type": "t1"}
{"index": {"_id": 8}}
{"name": "redis good hello", "filter_type": "t1"}

# 搜索
GET /significant_text_test/_search?size=0
{
  "query": {
    "match": {
      "name": "hello"
    }
  }, 
  "aggs": {
    "key_name_aggs": {
      "significant_text": {
        "field": "name",
        "min_doc_count": 4, 
        "filter_duplicate_text": true, 
        "background_filter": {
          "term": {
            "filter_type": "t1"
          }
        }
      }
    }
  }
}

# 结果
{
  "took" : 2,
  "timed_out" : false,
  "_shards" : {
    "total" : 1,
    "successful" : 1,
    "skipped" : 0,
    "failed" : 0
  },
  "hits" : {
    "total" : {
      "value" : 6,
      "relation" : "eq"
    },
    "max_score" : null,
    "hits" : [ ]
  },
  "aggregations" : {
    "key_name_aggs" : {
      "doc_count" : 6,
      "bg_count" : 5,
      "buckets" : [
        {
          "key" : "hello",
          "doc_count" : 6,
          "score" : 0.24999999999999994,
          "bg_count" : 4
        },
        {
          "key" : "good",
          "doc_count" : 5,
          "score" : 0.03472222222222222,
          "bg_count" : 4
        }
      ]
    }
  }
}

本文标签: ElasticsearchesaggssignificanttextBucket