我想用ES进行图书搜索.所以我决定将作者姓名和标题(作为嵌套文档)放入索引中,如下所示:
curl -XPUT localhost:9200/library/search_books/1 -d'{
"author": "one",
"books": [
{
"title": "two",
},
{
"title": "three",
}
]
}'
Run Code Online (Sandbox Code Playgroud)
我没有得到的结果是:我如何构建搜索查询,在搜索"一二"时只查找第二本书,在搜索"二三"时找不到任何内容,在搜索"一"时查找所有书籍?
当一个搜索词在我正在搜索的文档中不仅出现一次而且出现多次时,分数就会上升。虽然大多数时候可能需要这样做,但在我的情况下并非如此。
查询:
"query": {
"bool": {
"should": {
"nested": {
"path": "editions",
"query": {
"match": {
"title_author": {
"query": "look me up",
"operator": "and",
"boost": 2
}
}
}
}
},
"must": {
"nested": {
"path": "editions",
"query": {
"match": {
"title_author": {
"query": "look me up",
"operator": "and",
"fuzziness": 0.5,
"boost": 1
}
}
}
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
文档_1
{
"editions": [
{
"editionid": 1,
"title_author": "look me up look me up",
},
{
"editionid": 2,
"title_author": "something …Run Code Online (Sandbox Code Playgroud)