[elasticsearch笔记] aggregation-reverse_nested/sampler/significant_terms/significant_text

meta && typed_keys

GET /twitter/_search
{
  "size": 0,
  "aggs": {
    "titles": {
      "terms": {
        "field": "title"
      },
      "meta": {
        "color": "blue"
      }
    }
  }
}

GET /twitter/_search?typed_keys
{
  "aggregations": {
    "tweets_over_time": {
      "date_histogram": {
        "field": "date",
        "calendar_interval": "year"
      },
      "aggregations": {
        "top_users": {
          "top_hits": {
            "size": 1
          }
        }
      }
    }
  }
}

reverse_nested


PUT /issues
{
  "mappings": {
    "properties": {
      "tags": {
        "type": "keyword"
      },
      "comments": {
        "type": "nested",
        "properties": {
          "username": {
            "type": "keyword"
          },
          "comment": {
            "type": "text"
          }
        }
      }
    }
  }
}

PUT /issues/_doc/1
{
  "tags":["tag-1","tag-2"],
  "comments":[
    {
      "username":"zcj",
      "comment":"good"
    },
    {
      "username":"dyc",
      "comment":"ok"
    }
  ]
}

PUT /issues/_doc/2
{
  "tags":["tag-3","tag-2"],
  "comments":[
    {
      "username":"zwj",
      "comment":"bad"
    },
    {
      "username":"dyc",
      "comment":"fail"
    }
  ]
}

GET /issues/_search?size=0
{
  "query": {
    "match_all": {}
  },
  "aggs": {
    "comments": {
      "nested": {
        "path": "comments"
      },
      "aggs": {
        "top_usernames": {
          "terms": {
            "field": "comments.username"
          },
          "aggs": {
            "comment_to_issue": {
              "reverse_nested": {},
              "aggs": {
                "top_tags_per_comment": {
                  "terms": {
                    "field": "tags"
                  }
                }
              }
            }
          }
        }
      }
    }
  }
}

sampler/significant_terms/significant_text

# The shard_size parameter limits how many top-scoring documents are collected in the sample processed on each shard. The default value is 100.
POST /stackoverflow/_search?size=0
{
  "query": {
    "query_string": {
      "query": "tags:kibana OR tags:javascript"
    }
  },
  "aggs": {
    "sample": {
      "sampler": {
        "shard_size": 200
      },
      "aggs": {
        "keywords": {
          "significant_terms": {
            "field": "tags",
            "exclude": [
              "kibana",
              "javascript"
            ]
          }
        }
      }
    }
  }
}

POST /stackoverflow/_search?size=0
{
  "query": {
    "query_string": {
      "query": "tags:kibana OR tags:javascript"
    }
  },
  "aggs": {
    "low_quality_keywords": {
      "significant_terms": {
        "field": "tags",
        "size": 3,
        "exclude": [
          "kibana",
          "javascript"
        ]
      }
    }
  }
}

GET /_search
{
  "query": {
    "terms": {
      "force": [
        "British Transport Police"
      ]
    }
  },
  "aggregations": {
    "significant_crime_types": {
      "significant_terms": {
        "field": "crime_type"
      }
    }
  }
}

GET /_search
{
  "aggregations": {
    "forces": {
      "terms": {
        "field": "force"
      },
      "aggregations": {
        "significant_crime_types": {
          "significant_terms": {
            "field": "crime_type"
          }
        }
      }
    }
  }
}

GET /_search
{
  "aggs": {
    "hotspots": {
      "geohash_grid": {
        "field": "location",
        "precision": 5
      },
      "aggs": {
        "significant_crime_types": {
          "significant_terms": {
            "field": "crime_type"
          }
        }
      }
    }
  }
}

GET news/_search
{
  "query": {
    "match": {
      "content": "Bird flu"
    }
  },
  "aggregations": {
    "my_sample": {
      "sampler": {
        "shard_size": 100
      },
      "aggregations": {
        "keywords": {
          "significant_text": {
            "field": "content"
          }
        }
      }
    }
  }
}

GET news/_search
{
  "query": {
    "match": {
      "content": "elasticsearch"
    }
  },
  "aggs": {
    "sample": {
      "sampler": {
        "shard_size": 100
      },
      "aggs": {
        "keywords": {
          "significant_text": {
            "field": "content",
            "filter_duplicate_text": true
          }
        }
      }
    }
  }
}

GET news/_search
{
  "query": {
    "match": {
      "custom_all": "elasticsearch"
    }
  },
  "aggs": {
    "tags": {
      "significant_text": {
        "field": "custom_all",
        "source_fields": [
          "content",
          "title"
        ]
      }
    }
  }
}

GET news/_search
{
  "query": {
    "match": {
      "content": "madrid"
    }
  },
  "aggs": {
    "tags": {
      "significant_text": {
        "field": "content",
        "background_filter": {
          "term": {
            "content": "spain"
          }
        }
      }
    }
  }
}

你可能感兴趣的:(elasticsearch,笔记)