真人照片转二次元后怎么换画风?原照与二次元成图的两种用法
2026-11-21
2026-11-26 0
从商品索引中筛选一批指定编码时,在 Elasticsearch 的 terms 查询中,把候选值写成同一字段下的数组。只要字段中的一个已索引词项与任意候选值相同,文档就会命中。
打开 Kibana 的 Dev Tools Console,依次运行下面的请求。实测使用 Elasticsearch 9.4.0 的本地单节点和合成商品数据。请在空白测试索引上执行首个请求。将 SKU 和标签都定义为 keyword,并用 refresh=wait_for 等待写入可被搜索。
PUT /terms-demo
{
"mappings": {
"properties": {
"sku": {
"type": "keyword"
},
"labels": {
"type": "keyword"
}
}
}
}
POST /terms-demo/_bulk?refresh=wait_for
{"index":{"_id":"1"}}
{"sku":"KB-01","labels":["sale","usb"]}
{"index":{"_id":"2"}}
{"sku":"KB-02","labels":["usb"]}
{"index":{"_id":"3"}}
{"sku":"MS-01","labels":["wireless"]}

将一个 SKU 放在数组里。再用小写和前缀做对照,观察当前映射下的大小写与完整值要求。
GET /terms-demo/_search?filter_path=hits.total.value,hits.hits._id,hits.hits._source
{
"query": {
"terms": {
"sku": [
"KB-01"
]
}
},
"track_total_hits": true
}
GET /terms-demo/_search?filter_path=hits.total.value,hits.hits._id,hits.hits._source
{
"query": {
"terms": {
"sku": [
"kb-01",
"KB"
]
}
},
"track_total_hits": true
}
单独传一个候选值时也要保留数组。若只需传一个值且接口固定为单值,可以使用 term。
SKU 有两个候选值,任意命中一个的商品都会返回。标签字段本身也可以存多个值。若查询只用于筛选,把 terms 放进 bool.filter,这个条件就不会参与相关性评分。
GET /terms-demo/_search?filter_path=hits.total.value,hits.hits._id,hits.hits._source
{
"query": {
"terms": {
"sku": [
"KB-01",
"KB-02"
]
}
},
"track_total_hits": true
}
GET /terms-demo/_search?filter_path=hits.total.value,hits.hits._id,hits.hits._source
{
"query": {
"bool": {
"filter": [
{
"terms": {
"labels": [
"sale",
"wireless"
]
}
}
]
}
},
"track_total_hits": true
}
标签查询中,ID 1 含 sale,ID 3 含 wireless,两条记录各自命中一个候选标签。需要指定最少命中几个词项时,可以用 terms_set。
给结构化字符串选用 keyword 字段。对已有索引,先检查映射,确认有可用的 .keyword 子字段再使用它。对 text 字段,terms 比较的是分词后已索引的词项,全文检索可用 match。如果字段配置了 normalizer,精确匹配遵循归一化规则。单次 terms 查询默认最多提供 65,536 个候选词项,由 index.max_terms_count 控制。