我正在使用Elasticsearch,并使用WebRequest编写自己的包装器,因为NEST(通常的选择)令人费解地似乎缺乏插入项目并返回生成的ID的能力。
无论如何 - 一般方法没有问题。但是,任何HTML内容都按原样编入索引,即如果我在字段中有<strong>test</strong>
,则搜索“strong”查询会返回该项目。
我把它放在elasticsearch.yml中,基于我发现的随机留言板帖子:
index:
analysis:
analyzer:
htmlContentAnalyzer:
type: custom
tokenizer: standard
filter: standard
char_filter: html_strip
然后,我为我的索引'content'创建了一个映射,项目类型'news':
PUT http://localhost:9200/content/news/_mapping
{
"news" : {
"properties" : {
"TextContent" : {
"type" : "string",
"index" : "analyzed",
"analyzer" : "htmlContentAnalyzer",
"store" : "yes"
}
}
}
}
}
store
/ yes
只是为了“有趣”,它没有任何区别。以上给我200 OK。
但是,搜索会返回相同的结果。
什么无济于事的弹性搜索文档似乎令人震惊。看看这个页面:
http://www.elasticsearch.org/guide/reference/api/admin-indices-put-mapping.html
它简要介绍了映射的内容,并在映射部分说明了更多详细信息,即此页面:
http://www.elasticsearch.org/guide/reference/mapping/
......这似乎真的太可怕了。没有提到我找到的格式/对象图 - 没有提到“属性”,“类型”,“分析器”,“索引”等。右侧菜单上有一些部分,例如“_index”,但它们似乎是指整个项目?那指出了哪里?
所以我的问题在两个方面:
答案 0 :(得分:3)
在#elasticsearch(freenode IRC)上全部归功于chrismale -
搜索_all
并不好:用自己的分析器编制索引。查询我的TextContent
字段特别按预期工作。