gpt4 book ai didi

elasticsearch - 无法查询_all中的edge_ngram字段

转载 作者:行者123 更新时间:2023-12-03 01:54:05 24 4
gpt4 key购买 nike

因此,我正在建立一个索引,我想进行一次搜索,即可对一个字段进行部分单词edge_ngram搜索,而对其余字段进行更常规的搜索。据我了解,仅通过匹配_all就可以轻松做到这一点。但是我似乎无法使其工作。

我已经能够通过bool查询获得期望的结果,该查询分别搜索_all和特定的ngram字段,但这似乎是hackey,我想我只是缺少了一些简单的东西。

这只是一个最小的示例,以显示我在做什么以及它对我不起作用。

这是索引设置:

curl -XPUT "http://localhost:9200/test_index?pretty=true" -d'
{
"settings": {
"analysis": {
"filter": {
"edge_ngram_filter": {
"type": "edge_ngram",
"min_gram": 2,
"max_gram": 20
}
},
"analyzer": {
"edge_ngram_analyzer": {
"type": "custom",
"tokenizer": "standard",
"filter": [
"lowercase",
"edge_ngram_filter"
]
}
}
}
},
"mappings": {
"doc": {
"properties": {
"text_field": {
"type": "string",
"analyzer": "edge_ngram_analyzer",
"search_analyzer": "standard"
}
}
}
}
}'

并添加一个简单的文档:
curl -XPUT "http://localhost:9200/test_index/doc/1?pretty=true" -d'
{
"text_field": "Hello, World!"
}'

_all部分搜索无效。它返回一个空结果。
curl -XPOST "http://localhost:9200/test_index/_search?pretty=true" -d'
{
"query": {
"match": {
"_all": "hell"
}
}
}'

_所有全字搜索均有效
curl -XPOST "http://localhost:9200/test_index/_search?pretty=true" -d'
{
"query": {
"match": {
"_all": "hello"
}
}
}'

在特定 Realm 进行部分搜索是可行的
curl -XPOST "http://localhost:9200/test_index/_search?pretty=true" -d'
{
"query": {
"match": {
"text_field": "hell"
}
}
}'

vector 一词看起来也很好
curl -XGET "http://localhost:9200/test_index/doc/1/_termvector?fields=text_field&pretty=true"

我真的不知道我在做什么错。任何帮助,将不胜感激。

以下是有关我的环境的一些详细信息。
  • Elasticsearch版本:Version: 2.3.3, Build: 218bdf1/2016-05-17T15:40:04Z, JVM: 1.8.0_92
  • Linux操作系统:Arch Linux
  • 内核版本:4.4.3-1-custom
  • 最佳答案

    _all字段将所有字段的原始值组合为字符串,而不是为每个字段生成的术语。因此,在您的情况下,它不包含edge_ngram_analyzer生成的术语,仅包含text_field字段中的文本。就像任何其他文本字段一样,您可以为其指定分析器,等等。在您的示例中,它使用的是默认分析器。

    关于elasticsearch - 无法查询_all中的edge_ngram字段,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37958011/

    24 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com