ElasticSearch查询字符串

yfwxisqw  于 2022-11-22  发布在  ElasticSearch
关注(0)|答案(1)|浏览(206)

为什么我在第二个查询中不能得到与第三个查询相同的结果?我做错了什么?
1.我提出这样的疑问:

{
  "size": 20,
  "track_total_hits": false,
  "_source": [
    "title"
  ],
  "query": {
    "bool": {
      "must": [
        {
          "query_string": {
            "query": "63 ",
            "default_field": "title",
            "type": "phrase_prefix"
          }
        }
      ]
    }
  }
}

得到了这个结果:

{
  "hits": {
    "max_score": 13.483224,
    "hits": [
      {
        "_index": "products_2022_11_3_17_30_44_56920",
        "_type": "_doc",
        "_id": "19637",
        "_score": 13.483224,
        "_source": {
          "title": "Заднее стекло 6302BGNE"
        }
      }
    ]
  }
}

1.好的,在这之后我再输入一个字符:
"query": "63 2"
结果是空的:

"hits" : {
    "max_score" : null,
    "hits" : [ ]
  }
}

1.然后我再加一个字符:
"query": "63 21"
再次得到非空结果:

{
  "hits": [
    {
      "_index": "products_2022_11_3_17_30_44_56920",
      "_type": "_doc",
      "_id": "105863",
      "_score": 440.54578,
      "_source": {
        "title": "Лампа накаливания 63 21 0 151 620 BMW"
      }
    }
  ]
}

索引Map:

"title": {
          "type": "text",
          "fields": {
            "keyword": {
              "type": "keyword",
              "ignore_above": 256
            }
          }
        },

GET产品/_设置

{
  "products_2022_11_7_8_57_7_118045" : {
    "settings" : {
      "index" : {
        "routing" : {
          "allocation" : {
            "include" : {
              "_tier_preference" : "data_content"
            }
          }
        },
        "number_of_shards" : "1",
        "provided_name" : "products_2022_11_7_8_57_7_118045",
        "creation_date" : "1667800627119",
        "number_of_replicas" : "0",
        "uuid" : "GV6-5tzQQPavncFUcvq9NA",
        "version" : {
          "created" : "7170299"
        }
      }
    }
  }
}
vyu0f0g1

vyu0f0g11#

看起来你在你的title字段上使用了一些分析器,这是在搜索中创建令牌的方式,它不匹配你的搜索词。
我使用title字段的标准分析器,并索引您显示的示例文档,以及它在所有三个查询中给我的结果,如下所示:

{
    "size": 20,
    "track_total_hits": true,
    "_source": [
        "title"
    ],
    "query": {
        "bool": {
            "must": [
                {
                    "query_string": {
                        "query": "63 2",
                        "default_field": "title",
                        "type": "phrase_prefix"
                    }
                }
            ]
        }
    }
}

搜索结果

"hits": [
            {
                "_index": "74308224",
                "_type": "_doc",
                "_id": "2",
                "_score": 1.1689311,
                "_source": {
                    "title": "Лампа накаливания 63 21 0 151 620 BMW"
                }
            }
        ]

提供索引Map和设置有助于确定未提供预期结果的原因。

相关问题