XML文件内容的弹性搜索

Bib*_*hew 1 rest elasticsearch

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

  1. 这是否可以使用弹性搜索获得
  2. 我尝试了以下方法:

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

创建了一个映射:

  curl -XPUT 'http://localhost:9200/second/?pretty=1'  -d '
 {
        "mapping" : {
            "xmlfile" : {
                "properties" : {
                    "attachment": { "type" : "attachment" }
                }
            }
        }
    }
Run Code Online (Sandbox Code Playgroud)

索引XML文件:

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

试过搜索:

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

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

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

哪个给了我:

{
   "took": 14,
   "timed_out": false,
   "_shards": {
      "total": 5,
      "successful": 5,
      "failed": 0
   },
   "hits": {
      "total": 0,
      "max_score": null,
      "hits": []
   }
}
Run Code Online (Sandbox Code Playgroud)

它说0次点击.我也尝试将我的xml转换为JSON对象和索引.但这对我的计划来说是很多工作.有人可以帮我这个吗?当XML包含字符串时,为什么说0次命中?

Oll*_*ank 5

1.XML搜索 - 使用弹性搜索是否可以实现

是的,一点没错.但是,我会对你所拥有的方法采取不同的方法.我会改为

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