【问题标题】:Elasticsearch "search query term" returns 0 hints for nested object keys in _doc type indexElasticsearch“搜索查询词”为 _doc 类型索引中的嵌套对象键返回 0 个提示
【发布时间】:2021-05-11 05:37:15
【问题描述】:

我在 elasticsearch 中搜索时遇到问题。每当我尝试按以下 curl 之类的术语进行搜索时,都会得到我想要的结果。

curl --location --request GET 'http://xx.xx.xx.xx:xxxx/XXXXXX/_search' \
--header 'Content-Type: application/json' \
--data-raw '{
    "query": {
        "term": {
            "time": {
                "value": "2021-02-09T00:09:49.457Z",
                "boost": 1.0
            }
        }
    }
}
'

响应示例。该类型表示 _doc,因此嵌套查询应该以相同的方式工作。

{"hits": [
            {
                "_index": "XXXX",
                "_type": "_doc",
                "_id": "xxxxx",
                "_score": 1.0,
                "_source": { ... }
]}

但是,当我尝试搜索嵌套键时,我在响应中得到 0 次点击。

curl --location --request GET 'http://xx.xx.xx.xx:xxxx/XXXXXX/_search' \
--header 'Content-Type: application/json' \
--data-raw '{
    "query": {
        "term": {
            "code.type": {
                "value": "animals",
                "boost": 1.0
            }
        }
    }
}

知道可能出了什么问题吗?

【问题讨论】:

  • 查看索引映射会很有用。

标签: elasticsearch dsl elasticsearch-query


【解决方案1】:

如果您确定您尝试搜索的文档存在,请确保您的字段的索引映射以及“code”字段是否是使用“code.keyword”进行关键字搜索,如果出现以下情况,请删除“boost”字段它没有再次改变您的查询语法和策略,例如叶子查询

curl -XGET "http://xx.xx.xx.xx:xxxx/XXXXXX/_search" -H 'Content-Type: application/json' -d'{  "query": {"match": {    "code.type": "animals"  }}}'

如果你的字段是关键字

    curl -XGET "http://xx.xx.xx.xx:xxxx/XXXXXX/_search" -H 'Content-Type: application/json' -d'{  "query": {"match": {    "code.type": "animals"  }}}'

随时更新对话和评论。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-11-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-03-27
    • 1970-01-01
    • 2018-02-03
    相关资源
    最近更新 更多