如何在 ElasticSearch 控制台中构建 "Terms" 查询?
How to build a "Terms" query in ElasticSearch console?
总的来说,我对 ElasticSearch 和 NoQSL 还比较陌生。我的问题看起来很简单,但我似乎无法解决它。
我从中获取的索引看起来像这样:
"hits" : [
{
"_index" : "movie",
"_type" : "_doc",
"_id" : "255239",
"_score" : 1.0,
"_source" : {
"id" : 255239,
"title" : "Passport to Pimlico",
"original" : "Passport to Pimlico",
"lead" : "",
"text" : "blablabla",
"classification" : 0,
"year" : "1949",
"color" : "b&w",
"duration" : "85",
"url" : "some url",
"slug" : "something something",
"openingDate" : "1900-01-01T00:00:00",
"countries" : [
"GB"
],
"genres" : [
"Comedy",
"Action"
],
"producers" : [ ],
我正在尝试搜索与此简单数组中的任何术语匹配“流派”属性 内任何项目的任何记录' [“惊悚片”、“喜剧片”]'.
这是我在控制台中的查询:
GET movie/_search
{
"query": {
"terms": {
"genres": ["Thriller", "Comedy"]
}
}
}
此查询似乎有效,但返回 0 个结果。我做错了什么?
感谢任何帮助,谢谢。
试试这个,即查询 genres.keyword
而不是 genres
:
GET movie/_search
{
"query": {
"terms": {
"genres.keyword": ["Thriller", "Comedy"]
}
}
}
这应该有效:
GET movie/_search
{
"query": {
"bool:{
"should": {
"terms":
{
"genres": ["Thriller", "Comedy"]
}
}
}
}
}
Should
boolQuery 的出现类型将与提供的任何术语匹配文档(因为默认情况下 minimum_should_match
为 1)。
如果您想匹配两种类型的文档,请使用 minimum_should_match: 2
更多文档:https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-bool-query.html
总的来说,我对 ElasticSearch 和 NoQSL 还比较陌生。我的问题看起来很简单,但我似乎无法解决它。
我从中获取的索引看起来像这样:
"hits" : [
{
"_index" : "movie",
"_type" : "_doc",
"_id" : "255239",
"_score" : 1.0,
"_source" : {
"id" : 255239,
"title" : "Passport to Pimlico",
"original" : "Passport to Pimlico",
"lead" : "",
"text" : "blablabla",
"classification" : 0,
"year" : "1949",
"color" : "b&w",
"duration" : "85",
"url" : "some url",
"slug" : "something something",
"openingDate" : "1900-01-01T00:00:00",
"countries" : [
"GB"
],
"genres" : [
"Comedy",
"Action"
],
"producers" : [ ],
我正在尝试搜索与此简单数组中的任何术语匹配“流派”属性 内任何项目的任何记录' [“惊悚片”、“喜剧片”]'.
这是我在控制台中的查询:
GET movie/_search
{
"query": {
"terms": {
"genres": ["Thriller", "Comedy"]
}
}
}
此查询似乎有效,但返回 0 个结果。我做错了什么?
感谢任何帮助,谢谢。
试试这个,即查询 genres.keyword
而不是 genres
:
GET movie/_search
{
"query": {
"terms": {
"genres.keyword": ["Thriller", "Comedy"]
}
}
}
这应该有效:
GET movie/_search
{
"query": {
"bool:{
"should": {
"terms":
{
"genres": ["Thriller", "Comedy"]
}
}
}
}
}
Should
boolQuery 的出现类型将与提供的任何术语匹配文档(因为默认情况下 minimum_should_match
为 1)。
如果您想匹配两种类型的文档,请使用 minimum_should_match: 2
更多文档:https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-bool-query.html