【问题标题】:What is wrong in this elastic search query?这个弹性搜索查询有什么问题?
【发布时间】:2020-10-07 05:26:16
【问题描述】:

我不明白为什么我没有结果?使用 ES 2。

"query": {
      "filtered": {
         "query": {
            "match_all": {}
         },
         "filter": {
            "term": {
               "technical.techcolor": "red"
            }
         }
      }
   }

这是我正在搜索的来自 db 的信息。

{"technical":
        [{
         "techname22": "test",
         "techcolor":"red",
         "techlocation": "usa"
        }],
    "audio":
        {
        "someAudioMetadata": "test"
        }
    }

【问题讨论】:

标签: elasticsearch elasticsearch-query term-query


【解决方案1】:

由于您尚未指定映射,我正在考虑以下映射。

映射:

{
  "mappings": {
    "company": {
      "properties": {
        "technical": {
          "type": "nested"
        }
      }
    }
  }
}

搜索查询:

{
  "query": {
    "filtered": {
      "query": {
        "match_all": {

        }
      },
      "filter": {
        "nested": {
          "path": "technical",
          "filter": {
            "term": {
              "technical.techcolor": "red"
            }
          }
        }
      }
    }
  }
}

搜索结果:

"hits": {
        "total": 1,
        "max_score": 1.0,
        "hits": [
            {
                "_index": "demos",
                "_type": "company",
                "_id": "1",
                "_score": 1.0,
                "_source": {
                    "technical": [
                        {
                            "techname22": "test",
                            "techcolor": "red",
                            "techlocation": "usa"
                        }
                    ],
                    "audio": {
                        "someAudioMetadata": "test"
                    }
                }
            }
        ]
    }

要了解更多关于嵌套数据类型的信息,您可以参考这个官方documentation,查询和过滤上下文参考this

【讨论】:

  • @Ramix 你有没有机会仔细阅读我的回答,期待得到你的反馈,如果有帮助,请不要忘记点赞并接受:)
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-05-23
  • 2020-06-29
  • 2011-09-29
  • 2011-10-13
相关资源
最近更新 更多