XML文件内容的弹性搜索

时间:2015-01-02 09:28:13

标签: rest elasticsearch

我是弹性搜索新手。我的用例是在一些XML文件集中搜索文本。所以我的问题是。

  1. 使用弹性搜索
  2. 是否可以实现
  3. 我尝试了以下内容:

    安装了Elastic搜索,应用了附件插件

  4. 创建了一个映射:

      curl -XPUT 'http://localhost:9200/second/?pretty=1'  -d '
     {
            "mapping" : {
                "xmlfile" : {
                    "properties" : {
                        "attachment": { "type" : "attachment" }
                    }
                }
            }
        }
    

    索引XML文件:

    curl -XPOST "http://localhost:9200/second/xmlfile?pretty=1" -d '
           {
          "file" : "'`base64 D:\\games.xml | perl -pe 's/\n/\\n/g'`'"
           }
    

    尝试搜索:

     curl -XGET 'http://localhost:9200/second/xmlfile/_search?pretty=1'  -d '
    {
       "query" : {
          "text" : {
             "file" : "curField"  //currField is a string inside my xml
          }
       }
    }
    

    上面的搜索给了我SearchNotFound Exception,所以我

     curl -XGET 'http://localhost:9200/second/xmlfile/_search?pretty=1'  -d '
    {
       "query" : {
          "term" : {
             "file" : "curField"  //currField is a string inside my xml
          }
       }
    }
    

    哪位给了我:

    {
       "took": 14,
       "timed_out": false,
       "_shards": {
          "total": 5,
          "successful": 5,
          "failed": 0
       },
       "hits": {
          "total": 0,
          "max_score": null,
          "hits": []
       }
    }
    
    它说的是0次点击。 我也尝试将我的xml转换为JSON对象和索引。但这对我的计划来说是很多工作。有人可以帮我这个吗?当XML包含字符串时,为什么说0次命中?

1 个答案:

答案 0 :(得分:5)

  

1。 XML搜索 - 使用弹性搜索

是否可以实现

绝对是的。 但是,我对你所拥有的方法采取不同的方法。 我会改为

  1. 创建自定义分析器以解析XML数据。例如,如果您对代码不感兴趣,而只对代码中的数据感兴趣,请使用html strip char filter
  2. 将XML文档存储在单个字符串字段中 - attachment主要用于二进制数据,并且我猜测您的XML文档是ASCII或UTF-8。