我试图在任何地方寻找答案,但我没有成功找到它。我有一个简单的用户索引,我使用以下查询来获取一些结果:
1. curl -XGET 'localhost:9200/users/_search?pretty' -d'
{
"explain": true,
"query": {
"match": {
"skills": {
"query": "im looking for some business counseling",
"operator": "or",
"fuzziness": "auto",
"analyzer": "search_analyzer"
}
}
},
"sort": [
{"_score": "desc"}
],
}'
此查询成功地为我提供了所需的结果...现在我丢失的部分是如何使用以下查询(#2)来查询刚刚从上面的查询中获取的文档(#1)。 (顺便说一下,我尝试过使用elastic.co文档中的所有类型的复合查询,但问题是他们只根据不同的标准查询一组文档?或者我错了?):
2. "query": {
"match": {
"search": {
"query": "now I want to query the documents just fetched with this text",
"operator": "or",
"fuzziness": "auto",
"analyzer": "search_analyzer"
}
}
}
答案 0 :(得分:0)
因此,在重新阅读文档后,我最终找到了复合bool查询的答案......看起来像这样:
curl -XGET 'localhost:9200/users/_search?pretty' -d'
{
"explain": true,
"query": {
"bool": {
"should": [
{ "match": { "skills": "Im looking for somebody with business skills"}},
{ "bool": {
"should": [
{ "match": { "search": "someone is looking for my skills which are cooking,caking, and entertaining" }}
]
}}
]
}
},
"sort": [
{"_score": "desc"}
]
}'
索引的映射如下:
{
"settings": {
"analysis": {
"analyzer": {
"search_analyzer": {
"type": "custom",
"tokenizer": "punctuation",
"filter": ["lowercase","apostrophe","asciifolding","stop_analyzer","kstem"]
}
},
"tokenizer": {
"punctuation": {
"type": "pattern",
"pattern": "[ .,!?+&@=-]"
}
},
"filter": {
"stop_analyzer": {
"type": "stop"
}
}
}
},
"mappings": {
"users": {
"properties": {
"skills": {
"type": "string",
"norms": { "enabled": false },
"analyzer": "search_analyzer"
},
"search": {
"type": "string",
"norms": { "enabled": false },
"analyzer": "search_analyzer"
}
}
}
}
}