Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/search/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
<img src="//i.stack.imgur.com/RUiNP.png" height="16" width="18" alt="" class="sponsor tag img">elasticsearch 针对特定字段的ElasticSearch查询未给出结果_<img Src="//i.stack.imgur.com/RUiNP.png" Height="16" Width="18" Alt="" Class="sponsor Tag Img">elasticsearch - Fatal编程技术网 elasticsearch 针对特定字段的ElasticSearch查询未给出结果,elasticsearch,elasticsearch" /> elasticsearch 针对特定字段的ElasticSearch查询未给出结果,elasticsearch,elasticsearch" />

elasticsearch 针对特定字段的ElasticSearch查询未给出结果

elasticsearch 针对特定字段的ElasticSearch查询未给出结果,elasticsearch,elasticsearch,当我尝试对映射的某些字段运行查询时,我会得到一个空结果集,例如hits:[]。 以下是我的映射: @classmethod def get_mapping(cls): not_analyzed_str = {'type': 'string', 'index': 'not_analyzed'} stake_fields = { 'id': {'type': 'integer'}, 'user': not

当我尝试对映射的某些字段运行查询时,我会得到一个空结果集,例如hits:[]。 以下是我的映射:

@classmethod
def get_mapping(cls):
    not_analyzed_str = {'type': 'string',
                        'index': 'not_analyzed'}
    stake_fields = {
        'id': {'type': 'integer'},
        'user': not_analyzed_str,
        'user_id': {'type': 'integer'},
        'side': {'type': 'integer'},
        'amount': {'type': 'double'},
        'created': {'type': 'date'},
        'address': not_analyzed_str,
    }
    return {
        'properties': {
            'id': {'type': 'integer'},
            'description': {'type': 'string',
                            'analyzer': 'snowball'},
            'group': not_analyzed_str,
            'state': not_analyzed_str,
            'type': not_analyzed_str,
            'currency': not_analyzed_str,
            'username': not_analyzed_str,
            'user_id': {'type': 'integer'},
            'expires': {'type': 'date'},
            'created': {'type': 'date'},
            'stakes_acception_end': {'type': 'date'},
            'winner': {'type': 'integer'},
            'stakes': {'type': 'nested',
                       'properties': stake_fields},
        }
    }
我的问题是:

curl -XGET '_http://my.ip/main/core_bet/_search' -d '{
    "query": {
        "nested" : {
            "path":"stakes",
            "query" : {
                "bool": {
                    "should": [{
                        "match": {"user_id": 2}
                    }]
                }
            }
        }
    }
}'
我什么也得不到。但当我将匹配值更改为{side:0}时,我得到以下结果:

    {
  "username": "DenisDavydov",
  "expires": "2014-12-28T17:53:00+00:00",
  "user_id": 1,
  "description": "[bet-engine] 0 bugs (2014-12-28 19:53)",
  "created": "2014-12-24T17:53:37.722558+00:00",
  "stakes_acception_end": "2014-12-27T17:53:00+00:00",
  "winner": null,
  "currency": "xxx/xxx",
  "state": "fresh",
  "group": "",
  "type": "0_bugs",
  "id": 45,
  "stakes": [
    {
      "user_id": 2,
      "created": "2014-12-26T14:24:52.565039+00:00",
      "id": 1,
      "amount": 12,
      "user": "admin",
      "address": "xxxxxxxxxxx",
      "side": 0
    },
    {
      "user_id": 2,
      "created": "2014-12-26T14:52:02.709043+00:00",
      "id": 2,
      "amount": 2,
      "user": "admin",
      "address": "xxxxxxxxx",
      "side": 0
    }
  ]
}

很明显,索引中确实包含了一个与user_id:2匹配的记录,那么它有什么问题呢?如何修复它?

根据文档,您需要给出完整路径 链接-

所以


肯定能用。

你能试试{stacks.user\u id:2}
curl -XGET '_http://my.ip/main/core_bet/_search' -d '{
    "query": {
        "nested" : {
            "path":"stakes",
            "query" : {
                "bool": {
                    "should": [{
                        "match": {"stakes.user_id": 2}
                    }]
                }
            }
        }
    }
}'