【发布时间】:2015-11-13 20:34:32
【问题描述】:
我想知道如何搜索所有具有包含单词的字符串字段的文档。
我正在寻找一种在单词前后使用通配符和 * 的解决方案。 但它不好,因为它还检索包含包含该字符串的更大单词的文档。 https://www.elastic.co/guide/en/elasticsearch/guide/current/_wildcard_and_regexp_queries.html 即如果我搜索“新闻” 结果可以包含“Wikinews”,这不是我想要的。
我的索引是这样定义的:
PUT /index
{
"mappings" : {
"text" : {
"properties" : {
"text" : { "type" : "string", "index" : "not_analyzed" },
"url" : { "type" : "string"}
}
}
}
}
我想搜索给定单词将出现在“文本”字段中的文档 编辑 : 示例数据:
curl -XPUT 'http://localhost:9200/index/type/1' -d '
{
"url": "wikipedia.com",
"Text": "in the news",
}'
curl -XPUT 'http://localhost:9200/index/type/2' -d '
{
"url": "wikipedia.com",
"Text": "Click here for Wikinews",
}'
curl -XPUT 'http://localhost:9200/index/type/3' -d '
{
"url": "wikipedia.com",
"Text": "news for each page are those:",
}'
curl -XPUT 'http://localhost:9200/index/type/4' -d '
{
"url": "wikipedia.com",
"Text": "What are the news means to you",
}'
curl -XPUT 'http://localhost:9200/index/type/5' -d '
{
"url": "walla.com",
"Text": "today News are more ...",
}'
这应该返回文档 1,3,4,5 文档 5,因为搜索不区分大小写。 文档 2 不包括在内,因为它不是新闻这个词,它是不相关的更大词的一部分
感谢帮助
【问题讨论】:
-
您的数据集样本是什么样的?我假设新闻这个词不仅仅在字段文本中。
-
您能否提供更多关于您想要执行的查询类型、想要的结果和想要避免的结果的信息?
标签: elasticsearch