【问题标题】:Indexing a comma-separated value field in Elastic Search在 Elastic Search 中索引逗号分隔值字段
【发布时间】:2015-09-17 12:53:21
【问题描述】:

我正在使用 Nutch 抓取网站并将其编入 Elastic 搜索中。我的网站有元标记,其中一些包含逗号分隔的 ID 列表(我打算用于搜索)。例如:

contentTypeIds="2,5,15"。 (注意:没有方括号)。

当 ES 索引这个时,我无法搜索 contentTypeIds:5 并找到 contentTypeIds 包含 5 的文档;此查询仅返回 contentTypeIds 正好为“5”的文档。但是,我确实想找到 contentTypeIds 包含 5 的文档。

在 Solr 中,通过在 schema.xml 中将 contentTypeIds 字段设置为 multiValued="true" 来解决此问题。我找不到如何在 ES 中做类似的事情。

我是 ES 新手,所以我可能错过了一些东西。感谢您的帮助!

【问题讨论】:

    标签: elasticsearch


    【解决方案1】:

    创建custom analyzer,它将用逗号将索引文本拆分为标记。

    然后你可以尝试搜索。如果您不关心相关性,您可以使用过滤器来搜索您的文档。我的示例展示了如何尝试使用 term filter 进行搜索。

    您可以在下面找到如何使用 sense 插件来做到这一点。

    DELETE testindex
    
    PUT testindex
    {
        "index" : {
            "analysis" : {
                "tokenizer" : {
                    "comma" : {
                        "type" : "pattern",
                        "pattern" : ","
                    }
                },
                "analyzer" : {
                    "comma" : {
                        "type" : "custom",
                        "tokenizer" : "comma"
                    }
                }
            }
        }
    }
    
    PUT /testindex/_mapping/yourtype
    {
            "properties" : {
                "contentType" : {
                    "type" : "string",
                    "analyzer" : "comma"
                }
            }
    }
    
    PUT /testindex/yourtype/1
    {
        "contentType" : "1,2,3"
    }
    
    PUT /testindex/yourtype/2
    {
        "contentType" : "3,4"
    }
    
    PUT /testindex/yourtype/3
    {
        "contentType" : "1,6"
    }
    
    GET /testindex/_search
    {
        "query": {"match_all": {}}
    }
    
    GET /testindex/_search
    {
        "filter": {
            "term": {
               "contentType": "6"
            }
        }
    }
    

    希望对你有帮助。

    【讨论】:

      【解决方案2】:
      POST _analyze
      {
        "tokenizer": {
          "type": "char_group",
          "tokenize_on_chars": [
            "whitespace",
            "-",
            "\n",
            ","
          ]
        },
        "text": "QUICK,brown, fox"
      }
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2013-12-06
        • 1970-01-01
        • 2016-04-24
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2013-06-21
        • 1970-01-01
        相关资源
        最近更新 更多