DELETE products
PUT products
{
"settings": {
"number_of_shards": 1
}
}
POST /products/_bulk
{ "index": { "_id": 1 }}
{ "productID" : "XHDK-A-1293-#fJ3","desc":"iPhone" }
{ "index": { "_id": 2 }}
{ "productID" : "KDKE-B-9947-#kL5","desc":"iPad" }
{ "index": { "_id": 3 }}
{ "productID" : "JODL-X-1937-#pV7","desc":"MBP" }
GET /products
# iPhone 查询不到,iphone可以查询
POST /products/_search
{
"query": {
"term": {
"desc": {
//"value": "iPhone"
"value":"iphone"
}
}
}
}
# keyword iPhone可以查询,iphone查询不到
POST /products/_search
{
"query": {
"term": {
"desc.keyword": {
"value": "iPhone"
//"value":"iphone"
}
}
}
}
# 查询不到
POST /products/_search
{
"query": {
"term": {
"productID": {
"value": "XHDK-A-1293-#fJ3"
}
}
}
}
# keyword 可以查询
# explain 查询的详细解释
POST /products/_search
{
//"explain": true,
"query": {
"term": {
"productID.keyword": {
"value": "XHDK-A-1293-#fJ3"
}
}
}
}
# constant_score 不考虑文档得分的情况下执行一个查询
POST /products/_search
{
"explain": true,
"query": {
"constant_score": {
"filter": {
"term": {
"productID.keyword": "XHDK-A-1293-#fJ3"
}
}
}
}
}
DELETE products
DELETE groups
# 设置 position_increment_gap
# position_increment_gap 是 Elasticsearch 中映射字段属性的一部分,用于控制文本字段中词项之间的位置增量。位置增量是指在全文搜索中词项之间的距禋。
# 主要使用场景:
# Phrase Searching: 在执行短语搜索时,位置增量可以影响词项匹配的准确性。通过调整 position_increment_gap,您可以控制 Elasticsearch 是否将字段值中相邻的词项视为一个短语。
# Synonym Analysis: 当处理同义词时,有时希望多个同义词共享相同的位置增量,以便它们被视为等效的词项。
# Token Filter Behavior: 位置增量还可以影响分析器和令牌过滤器的行为,例如在构建搜索引擎时控制关键字的匹配方式。
PUT groups
{
"mappings": {
"properties": {
"names":{
"type": "text",
"position_increment_gap": 0
}
}
}
}
GET groups/_mapping
POST groups/_doc
{
"names": [ "John Water", "Water Smith"]
}
POST groups/_search
{
"query": {
"match_phrase": {
"names": {
"query": "Water Water",
"slop": 100
}
}
}
}
POST groups/_search
{
"query": {
"match_phrase": {
"names": "Water Smith"
}
}
}
DELETE groups
标签:基于,-#,08,search,products,groups,query,POST,词项
From: https://blog.csdn.net/zhouweiye2012/article/details/141887819