繁体   English   中英

从字段中提取关键字

[英]Extract keywords from fields

我想编写一个查询来分析一个或多个字段?

即当前的分析器要求文本起作用,而不是传递文本,我想传递字段值。

如果我有这样的文件

{
    "desc": "A document description",
    "name": "This name is not original",
    "amount": 3000
}

我想返回类似下面的内容

{
    "desc": ["document", "description"],
    "name": ["name", "original"],
    "amount": 3000
}

您可以使用术语向量或多术语向量来实现所需的功能:

https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-multi-termvectors.html

您必须指定所需字段的ID以及字段,它会为您拥有的每个文档返回一个经过分析的标记数组,以及可以轻松禁用的某些其他信息。

GET /exampleindex/_doc/_mtermvectors
{
  "ids": [
    "1","2"
  ],
  "parameters": {
    "fields": [
      "*"
    ]
  }
}

将返回以下内容:

"docs": [
    {
      "_index": "exampleindex",
      "_type": "_doc",
      "_id": "1",
      "_version": 2,
      "found": true,
      "took": 0,
      "term_vectors": {
        "desc": {
          "field_statistics": {
            "sum_doc_freq": 5,
            "doc_count": 2,
            "sum_ttf": 5
          },
          "terms": {
            "amazing": {
              "term_freq": 1,
              "tokens": [
                {
                  "position": 1,
                  "start_offset": 3,
                  "end_offset": 10
                }
              ]
            },
            "an": {
              "term_freq": 1,
              "tokens": [
                {
                  "position": 0,
                  "start_offset": 0,
                  "end_offset": 2
                }
              ]
            }

嗯,这是另一种情况。 要在字段上使用分析器,必须在映射中声明它,就像在文档中看到的那样。 但是,如果将分析器与映射中的某个字段相关联,则将分析所有字段值。 分析器更改了在lucene的反向索引中对文本进行索引的方式-仅更改了如何检索文本-但未更改值的内容。 因此,只有在需要时,您才可以分析字段并调用_analyze api。 如果您希望在某些情况下以其他方式检索文本,则方案将再次更改。 根据我的说法,对于最后一种情况,更快,更简单的解决方案是复制您的字段,一次使用分析仪,第二次不使用

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM