我是elasticsearch的新手,我需要编写如下所述的查询
我有一个像这样的文档的elasticsearch索引
数字表示书中单词条目
{
"words": { # words listed below are different in every document
"cat": 7,
"monkey": 4,
"mouse": 10,
...
}
我想按单词"cat "搜索文档。(不是"猫"),"猴子";例如"老鼠"。如何编写查找"猫"、"猴子"的查询?和";mouse"在文件中考虑它们的值在记分?
乌利希期刊指南。示例:我有文档
{ # doc1
"words": {
"cat": 7,
"monkey": 4,
"mouse": 10,
}
}
{ # doc2
"words": {
"Cat": 20,
"monkeys": 40,
"mouse": 10,
}
}
{ # doc3
"words": {
"Dog": 10,
"monkey": 2,
"human": 10,
}
}
# I am searching by words "cats", "monkey", "mouse"
# I want to get doc2 as the most relevant result (because of words matches and entries quantity).
# doc1 should be the second result (words do match, but there are less entries).
# doc3 is the third result (too few words matches)
任何想法?
我不知道我理解的是否正确但是你想要搜索"cats"并返回带有单词"cat", "monkey"one_answers"mouse".
运行我做的这个例子,看看它是否适合你。
PUT my-index-000001
{
"mappings" : {
"properties" : {
"words" : {
"properties" : {
"count" : {
"type" : "text"
},
"key" : {
"type" : "text",
"analyzer": "english"
}
}
}
}
}
}
POST my-index-000001/_doc/1
{
"words": [
{
"key": "cat",
"count": "7"
},
{
"key": "monkey",
"count": "4"
},
{
"key": "mouse",
"count": "10"
}
]
}
GET my-index-000001/_search
{
"query": {
"match": {
"words.key":{
"query": "cats"
}
}
}
}