ElasticSearch nested类型求聚合

文章目录

正则查询

POST bdp_dev_profile_user_basic_label/_search
{
  "query": {
    "regexp":{
      "office_company.keyword": ".*,dy,.*"
    }
  }
}

PUT my_example/_doc/1
{
  "content":"This is a good network"
}


POST my_example/_search
{
  "query": {
    "regexp":{
      "content":"net.*"
    }
  }
}

查询mapping

GET /bdp_dev_profile_user_basic_label/_mapping

匹配查询

POST /bdp_dev_profile_user_basic_label/_search
{
  "query": {
    "bool": {
      "must": []
  , "should": [
    {"match": {
      "office_company": "dy"
    }}
  ]
      
    }
  }
}

term查询

POST /bdp_dev_profile_user_basic_label/_search
{
  "query": {
    "bool": {
      "must": [
        {
          "term": {
            "7days_appstart": {
              "value": "1"
            }
          }
        }
      ]
    }
  }
}
#1027

POST /bdp_dev_profile_user_basic_label/_search
{
  "query": {
    "bool": {
      "must": [
        {
          "term": {
            "7days_goodsdetail": {
              "value": "1"
            }
          }
        }
      ]
    }
  }
}

#284





#33
POST /bdp_dev_profile_user_basic_label/_search
{
  "query": {
    "bool": {
      "must": [
        {
          "term": {
            "7days_appstart": {
              "value": "1"
            }
          }
        },
        {
          "match": {
            "office_company": "dy"
          }
        }
      ]
    }
  }
}


#32
POST /bdp_dev_profile_user_basic_label/_search
{
  "query": {
    "bool": {
      "must": [
        {
          "term": {
            "user_id": {
              "value": "1062717"
            }
          }
        }
      ]
    }
  }
}

聚合查询
buy_goods_brand是数组,聚合后是数组内元素去重,count为1

POST /bdp_dev_profile_user_basic_label/_search
{
  "query": {
    "bool": {
      "must": [
        {
          "term": {
            "user_id": {
              "value": "1942411"
            }
          }
        }
      ]
    }
  }
  , "aggs": {
    "agg_by_buy_goods_brand": {
      "terms": {
        "field": "buy_goods_brand",
        "size": 10
      }
    }
  }
}

脚本查询

POST /bdp_dev_profile_user_basic_label/_search
{
  "query": {
    "term": {
      "user_id": {
        "value": "1154471"
      }
    }
  },"script_fields": {
    "buy_goods_brand": {
      "script": {
        "source": "doc['buy_goods_brand'].length"
      }
    }
  }
}

查询所有索引

GET /_cat/indices

删除索引

DELETE es_latent_buy_brands_frequency

nested类型聚合:

PUT es_latent_buy_brands_frequency
{
  "settings": {
    "number_of_replicas": 1
    , "number_of_shards": 3
  }, 
  "mappings": {
    "doc": {
      "properties": {
        "user_id":{
          "type": "keyword"
        },
        "latent_buy_brand_frequency":{
          "type": "nested",
          "properties": {
            "name":{
              "type":"keyword"
            }
          }
        }
      }
    }
  }
}

POST es_latent_buy_brands_frequency/_search

GET es_latent_buy_brands_frequency/_mapping

POST es_latent_buy_brands_frequency/_search
{
  "query": {
    "term": {
      "user_id": {
        "value": "1750119"
      }
    }
  }
}

POST es_latent_buy_brands_frequency/_search
{
  "aggs": {
    "buy_goods_brand": {
      "nested": {
        "path": "latent_buy_brand_frequency"
      },
      "aggs": {
        "agg_by_buy_goods_brand": {
          "terms": {
            "field": "latent_buy_brand_frequency.name",
            "size": 10
          }
        }
      }
    }
  }
}
上一篇:nested exception is java.lang.IndexOutOfBoundsException: Index: 0, Size: 0


下一篇:nacos部署手册