elasticsearch - 查询elasticsearch返回所有文档

标签 elasticsearch analyzer

我想知道为什么搜索特定术语会返回索引的所有文档,而不返回包含所请求术语的文档。

这是索引以及如何设置它:
(使用elasticsearch头插件浏览器界面)

{
  "settings": {
    "number_of_replicas": 1,
    "number_of_shards": 1,
    "analysis": {
      "filter": {
        "dutch_stemmer": {
          "type": "dictionary_decompounder",
          "word_list": [
            "koud",
            "plaat",
            "staal",
            "fabriek"
          ]
        },
        "snowball_nl": {
          "type": "snowball",
          "language": "dutch"
        }
      },
      "analyzer": {
        "dutch": {
          "tokenizer": "standard",
          "filter": [
            "length",
            "lowercase",
            "asciifolding",
            "dutch_stemmer",
            "snowball_nl"
          ]
        }
      }
    }
  }
}

{
  "properties": {
    "test": {
      "type": "string",
      "fields": {
        "dutch": {
          "type": "string",
          "analyzer": "dutch"
        }
      }
    }
  }
}

然后我添加了一些文档:
{"test": "ijskoud"}
{"test": "plaatstaal"}
{"test": "kristalfabriek"}

因此,现在在触发“plaat”搜索时,人们会希望搜索将返回包含“plaatstaal”的文档。
{
  "match": {
    "test": "plaat"
  }
}

但是为我节省了更多的搜索,elasticsearch会恢复所有文档的大小,无论其文本内容如何。
我在这里想念什么吗?
有趣的是:使用GET或POST时有所不同。尽管使用后者不会带来任何成功,但GET会返回所有文档。

任何帮助深表感谢。

最佳答案

您需要配置索引以使用自定义分析器:

PUT /some_index
{
  "settings": {
     ...
  },
  "mappings": {
    "doc": {
      "properties": {
        "test": {
          "type": "string",
          "analyzer": "dutch"
        }
      }
    }
  }
}

如果您有更多使用此分析器的字段,并且不想为每个分析器指定,则可以对该索引中的特定类型执行以下操作:
  "mappings": {
    "doc": {
      "analyzer": "dutch"
    }
  }

如果希望该索引中的所有类型都使用自定义分析器:
  "mappings": {
    "_default_": {
      "analyzer": "dutch"
    }
  }

要以简单的方式测试分析仪:
GET /some_index/_analyze?text=plaatstaal&analyzer=dutch

这将是执行步骤的完整列表:
DELETE /some_index

PUT /some_index
{
  "settings": {
    "number_of_replicas": 1,
    "number_of_shards": 1,
    "analysis": {
      "filter": {
        "dutch_stemmer": {
          "type": "dictionary_decompounder",
          "word_list": [
            "koud",
            "plaat",
            "staal",
            "fabriek"
          ]
        },
        "snowball_nl": {
          "type": "snowball",
          "language": "dutch"
        }
      },
      "analyzer": {
        "dutch": {
          "tokenizer": "standard",
          "filter": [
            "length",
            "lowercase",
            "asciifolding",
            "dutch_stemmer",
            "snowball_nl"
          ]
        }
      }
    }
  },
  "mappings": {
    "doc": {
      "properties": {
        "test": {
          "type": "string",
          "analyzer": "dutch"
        }
      }
    }
  }
}

POST /some_index/doc/_bulk
{"index":{}}
{"test": "ijskoud"}
{"index":{}}
{"test": "plaatstaal"}
{"index":{}}
{"test": "kristalfabriek"}

GET /some_index/doc/_search
{
  "query": {
    "match": {
      "test": "plaat"
    }
  }
}

搜索结果:
{
   "took": 1,
   "timed_out": false,
   "_shards": {
      "total": 1,
      "successful": 1,
      "failed": 0
   },
   "hits": {
      "total": 1,
      "max_score": 1.987628,
      "hits": [
         {
            "_index": "some_index",
            "_type": "doc",
            "_id": "jlGkoJWoQfiVGiuT_TUCpg",
            "_score": 1.987628,
            "_source": {
               "test": "plaatstaal"
            }
         }
      ]
   }
}

关于elasticsearch - 查询elasticsearch返回所有文档,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26502397/

相关文章:

c++ - 误报 : Undefined or garbage value returned to caller

elasticsearch - 如何将停用词添加到 ElasticSearch 中的默认列表

java - 如何知道两个类是否实现了一个公共(public)接口(interface)?

elasticsearch - 没有从 elasticsearch 获得术语向量结果?

java - 使用 java api 配置 elasticsearch 映射

elasticsearch - 具有英语分析器的elasticsearch同义词过滤器

elasticsearch - 使用Elasticsearch索引7TB数据FScrawler在一段时间后停止

querydsl - Elasticsearch DSL:多种聚合

functional-programming - 函数式编程语言的静态分析器,例如Scheme

c# - 声音分析器,使用naudio获得48000个样本/秒的声音。我可以使用1024的循环样本大小吗?