2015-01-02 191 views
1

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

  1. 这是可以实现的使用弹性搜索
  2. 我试过如下:

    安装弹性搜索,应用安装插件

创建一个映射:

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例外,这样的id

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命中?

回答

5

1。 XML搜索 - 这是否可以使用弹性搜索

是的绝对。 但是我会采取不同的方法来处理你的问题。 我会改为

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