【问题标题】:Elastic search not giving results弹性搜索不给出结果
【发布时间】:2016-06-10 19:53:37
【问题描述】:

我已经使用 ES 有一段时间了,但是今天不行。我重新创建了我的 docker-compose(可以在那里 smt 吗?),这些是我在 ES 中的数据:

编辑:这是我的输入(这里是_source = False

{'mappings': {'doc': {'_all': {'enabled': False}, 'dynamic': False, 'properties': {u'string': {'index': 'not_analyzed', 'type': 'string'}, '_time': {'index': 'not_analyzed', 'type': 'date'}, u'float': {'index': 'not_analyzed', 'type': 'float'}, u'datetime': {'index': 'not_analyzed', 'type': 'date'}, u'boolean': {'index': 'not_analyzed', 'type': 'boolean'}, u'integer': {'index': 'not_analyzed', 'type': 'long'}}, '_source': {'enabled': False}}}}

架构:

{
  "07533744-b0e6-4a2f-8e94-1f7501589fee": {
    "aliases": {},
    "mappings": {
      "doc": {
        "dynamic": "false",
        "properties": {
          "_time": {
            "type": "date",
            "format": "strict_date_optional_time||epoch_millis"
          },
          "boolean": {
            "type": "boolean"
          },
          "datetime": {
            "type": "date",
            "format": "strict_date_optional_time||epoch_millis"
          },
          "float": {
            "type": "float"
          },
          "integer": {
            "type": "long"
          },
          "string": {
            "type": "string",
            "index": "not_analyzed"
          }
        }
      }
    },
    "settings": {
      "index": {
        "creation_date": "1465555846775",
        "number_of_shards": "5",
        "number_of_replicas": "1",
        "uuid": "-nZGMXbFRryraL0gPnr80g",
        "version": {
          "created": "2030399"
        }
      }
    },
    "warmers": {}
  }
}

带有match_all查询的文档(一些):

{
  "took": 15,
  "timed_out": false,
  "_shards": {
    "total": 5,
    "successful": 5,
    "failed": 0
  },
  "hits": {
    "total": 10,
    "max_score": 1,
    "hits": [
      {
        "_index": "07533744-b0e6-4a2f-8e94-1f7501589fee",
        "_type": "doc",
        "_id": "49279857-84a7-4570-ad8e-9051079ca0ac",
        "_score": 1,
        "_source": {
          "doc": {
            "string": "1",
            "_time": "2016-06-10T12:50:59.509593",
            "float": 1.1,
            "datetime": "2016-06-10T12:50:59.497620",
            "boolean": false,
            "integer": 1
          }
        }
      },

现在查询: {"query": {"bool": {"must": [{"match": {"integer": 1}}]}}}

返回

{
  "took": 4,
  "timed_out": false,
  "_shards": {
    "total": 5,
    "successful": 5,
    "failed": 0
  },
  "hits": {
    "total": 0,
    "max_score": null,
    "hits": []
  }
}

知道问题出在哪里吗?

编辑: 用 curl 查询 curl -XGET -d '{"query": {"bool": {"must": [{"match": {"integer": 1}}]}}}' http://192.168.99.100:9200/07533744-b0e6-4a2f-8e94-1f7501589fee/doc/_search(无结果)

curl -XGET -d '{"query": {"bool": {"must": [{"match": {"_id": "49279857-84a7-4570-ad8e-9051079ca0ac"}}]}}}' http://192.168.99.100:9200/07533744-b0e6-4a2f-8e94-1f7501589fee/doc/_search(得到结果)

【问题讨论】:

    标签: elasticsearch


    【解决方案1】:

    改用term 查询:

    {
      "query": {
        "bool": {
          "must": [
            {
              "term": {
                "integer": 1
              }
            }
          ]
        }
      }
    }
    

    更新

    请注意,您的文档不符合您向我们展示的映射。

        "_source": {
          "doc": {
            "string": "1",
            "_time": "2016-06-10T12:50:59.509593",
            "float": 1.1,
            "datetime": "2016-06-10T12:50:59.497620",
            "boolean": false,
            "integer": 1
          }
        }
    

    应该是这样的,即没有doc 字段。

        "_source": {
            "string": "1",
            "_time": "2016-06-10T12:50:59.509593",
            "float": 1.1,
            "datetime": "2016-06-10T12:50:59.497620",
            "boolean": false,
            "integer": 1
    
        }
    

    【讨论】:

    • 同样的结果。它以前与比赛一起工作。这可能是弹性搜索图像的错误或问题。或我的电脑。其余的都对吗?
    • 奇怪,您是如何运行查询的?
    • 你能用你通过 curl 做的查询来更新你的问题吗?
    • 我提出了 curl 查询。我实际上可以重新创建整个事情
    • 与您拥有的映射相比,您的文档是错误的。您不应该将所有字段都包含在 doc 对象中,否则映射将不适用。您的所有字段都应该是 `_source` 的直接子项
    【解决方案2】:

    尝试您想要的相同查询,但稍作更改

    GET 07533744-b0e6-4a2f-8e94-1f7501589fee/doc/_search
    {
       "query": {
          "bool": {
             "should": [
                {
                   "match": {
                      "doc.integer": 1
                   }
                }
             ]
          }
       }
    }
    

    使用 doc.integer 而不是 integer

    【讨论】:

    • @EsseTi 我已经插入了上面给出的相同映射和文档,它对我来说工作正常。你之前尝试的甚至对我都不起作用,但这是
    • @EsseTi 你是在使用 sense 插件还是 curl 请求来查询 elasticsearch..?
    猜你喜欢
    • 1970-01-01
    • 2015-12-29
    • 2019-03-02
    • 1970-01-01
    • 2012-01-24
    • 1970-01-01
    • 1970-01-01
    • 2021-02-10
    • 1970-01-01
    相关资源
    最近更新 更多