真人照片转二次元后怎么换画风?原照与二次元成图的两种用法
2026-11-21
2026-11-26 0
下面把三篇标题写进 Elasticsearch 9.2.0,再逐条执行全文搜索、完整值查询和高亮查询。打开 Kibana 的 Dev Tools → Console,从创建实验索引开始,可用返回的 ID 检查每次查询。
把 title 映射为带标准分析器的 text 字段,同时保留 title.raw 这个 keyword 子字段,分别用于全文查询和完整值匹配。
PUT /search_query_lab_b37
{
"mappings": {
"properties": {
"title": {
"type": "text",
"analyzer": "standard",
"fields": { "raw": { "type": "keyword" } }
},
"status": { "type": "keyword" },
"seq": { "type": "integer" }
}
}
}
POST /search_query_lab_b37/_bulk?refresh=wait_for
{"index":{"_id":"1"}}
{"title":"Quick Brown Fox","status":"published","seq":1}
{"index":{"_id":"2"}}
{"title":"Quick Fox Guide","status":"published","seq":2}
{"index":{"_id":"3"}}
{"title":"Brown Bear Notes","status":"draft","seq":3}
// 创建索引 acknowledged = true;Bulk errors = false,写入 3 条
两种索引方式来自同一个 title 值,写入时只传 title。status 用于按完整状态值过滤。Bulk 的 refresh=wait_for 会等到本次变更对搜索可见,seq 仅用于固定教程里的输出顺序。
对 title 搜索 quick brown,分别观察默认 OR 和显式 AND 的命中集合。
GET /search_query_lab_b37/_search?filter_path=hits.total.value,hits.hits._id,hits.hits._source.title,hits.hits.highlight
{
"query": {
"match": {
"title": "quick brown"
}
},
"sort": [
{
"seq": "asc"
}
]
}
// 命中 3 条,ID 1, 2, 3
GET /search_query_lab_b37/_search?filter_path=hits.total.value,hits.hits._id,hits.hits._source.title,hits.hits.highlight
{
"query": {
"match": {
"title": {
"query": "quick brown",
"operator": "and"
}
}
},
"sort": [
{
"seq": "asc"
}
]
}
// 命中 1 条,ID 1
标准分析器会把标题拆成词项,并把英文字母转成小写。默认 OR 至少命中一个查询词,显式 AND 要命中两个词。AND 仍允许词序变化和词之间有间隔,需要按词序匹配时可考虑 match_phrase。
用相同数据比较原样输入、全小写输入以及查询字段选错时的结果。
GET /search_query_lab_b37/_search?filter_path=hits.total.value,hits.hits._id,hits.hits._source.title,hits.hits.highlight
{
"query": {
"term": {
"title.raw": "Quick Brown Fox"
}
},
"sort": [
{
"seq": "asc"
}
]
}
// 命中 1 条,ID 1
GET /search_query_lab_b37/_search?filter_path=hits.total.value,hits.hits._id,hits.hits._source.title,hits.hits.highlight
{
"query": {
"term": {
"title.raw": "quick brown fox"
}
},
"sort": [
{
"seq": "asc"
}
]
}
// 命中 0 条
GET /search_query_lab_b37/_search?filter_path=hits.total.value,hits.hits._id,hits.hits._source.title,hits.hits.highlight
{
"query": {
"term": {
"title": "Quick Brown Fox"
}
},
"sort": [
{
"seq": "asc"
}
]
}
// 命中 0 条
title.raw 没有配置 normalizer,完整值需要保留大小写和空格。term 按给定词项查找,title 中保存的是分析后的多个词项,因此直接拿整句查 title 会得到零条。业务中按状态、编号等值筛选时也可以使用 term,并将它放在 bool.filter 中。
保留相同的全文查询,再限定 status 为 published,为返回的标题标记命中的词。
GET /search_query_lab_b37/_search?filter_path=hits.total.value,hits.hits._id,hits.hits._source.title,hits.hits.highlight
{
"query": {
"bool": {
"must": [
{
"match": {
"title": "quick brown"
}
}
],
"filter": [
{
"term": {
"status": "published"
}
}
]
}
},
"sort": [
{
"seq": "asc"
}
],
"highlight": {
"pre_tags": [
""
],
"post_tags": [
""
],
"encoder": "html",
"fields": {
"title": {
"number_of_fragments": 0
}
}
}
}
// 命中 2 条,ID 1, 2
// ID 1 的 highlight.title[0] = Quick Brown Fox
// ID 2 的 highlight.title[0] = Quick Fox Guide
查询部分决定哪些文档返回。highlight 则把标记后的文本放在每条结果的 highlight.title 数组里,_source.title 保留原样。number_of_fragments 设为 0 会返回整个标题,适合短字段。展示时可优先读高亮数组,缺少片段时回退到原标题。
面向搜索框的输入使用 text 和 match,面向完整值筛选使用 keyword 和 term。结果列表可以从每条命中的 highlight 数组取展示片段,同时保留原始标题供回退。