elasticsearch,Php,elasticsearch" /> elasticsearch,Php,elasticsearch" />

Php 在elasticsearch中搜索精确值将返回许多结果

Php 在elasticsearch中搜索精确值将返回许多结果,php,elasticsearch,Php,elasticsearch,我正在对官方的elasticsearch php客户端使用以下请求 private function getAllStatisticsByDomain() { $params = [ 'index' => 'stats', 'type' => 'domain_stats', 'size' => 99, 'body' => [ 'query' => [ 'match' =&

我正在对官方的elasticsearch php客户端使用以下请求

  private function getAllStatisticsByDomain() {
    $params = [
      'index' => 'stats',
      'type' => 'domain_stats',
      'size' => 99,
      'body' => [
        'query' => [
          'match' => [
            'domain' => 'http://veehouder.cono.nl',
          ],
        ],
      ],
    ];

    $response = $this->getElasticClient()->search($params);


    return $response['hits']['hits'];
  }
前4个结果都有domain=>字段,但它还检索更多没有值“”的结果(请参见屏幕截图)

我还有一个函数,其中该请求工作正常,但位于日期字段中

  private function getAllStatisticsByDay() {
    $params = [
      'index' => 'stats',
      'type' => 'domain_stats',
      'size' => 99,
      'body' => [
        'query' => [
          'match' => [
            'date' => date('Y-m-d'),
          ],
        ],
      ],
    ];

    $response = $this->getElasticClient()->search($params);


    return $response['hits']['hits'];
  }
谁能解释一下为什么函数getAllStatisticsByDomain()检索的结果比我想要的多

这是我的索引函数:

/**
 * @param $id
 * @param $domain
 * @param $googlePSMobileScore
 * @param $googlePSMobileUsabilityScore
 * @param $googlePSDesktopScore
 * @param $mozPDA
 * @param $mozUPA
 */
function insert($id, $domain, $googlePSMobileScore, $googlePSMobileUsabilityScore, $googlePSDesktopScore, $mozPDA, $mozUPA, $date) {
  $params = [
    'index' => 'stats',
    'type' => 'domain_stats',
    'id' => $id,
    'body' => [
      'domain' => $domain,
      'googlePSMobileScore' => $googlePSMobileScore,
      'googlePSMobileUsabilityScore' => $googlePSMobileUsabilityScore,
      'googlePSDesktopScore' => $googlePSDesktopScore,
      'mozPDA' => $mozPDA,
      'mozUPA' => $mozUPA,
      'date' => $date,
    ],
  ];

  getElasticClient()->index($params);
}
我的字段映射:

{
    "stats": {
        "mappings": {
            "domain_stats": {
                "properties": {
                    "date": {
                        "type": "date",
                        "format": "strict_date_optional_time||epoch_millis"
                    },
                    "domain": {
                        "type": "string"
                    },
                    "googlePSDesktopScore": {
                        "type": "long"
                    },
                    "googlePSMobileScore": {
                        "type": "long"
                    },
                    "googlePSMobileUsabilityScore": {
                        "type": "long"
                    },
                    "mozPDA": {
                        "type": "double"
                    },
                    "mozUPA": {
                        "type": "double"
                    }
                }
            }
        }
    }
}

问题是您的
字段是一个已分析的字符串,不应对其进行分析。您需要删除索引并使用以下映射重新创建它:

                "domain": {
                    "type": "string",
                    "index": "not_analyzed"
                },
然后,您需要重新编制数据索引,并按如下方式查询数据,它将起作用:

  'body' => [
    'query' => [
      'term' => [
        'domain' => 'http://veehouder.cono.nl',
      ],
    ],
  ],

尝试使用
term
而不是
match
当运行
curl-XGET localhost:9200/stats/domain\u stats/\u mapping
时,您会得到什么!我用curl-XGET localhost:9200/stats/domain\u stats/\u mapping返回的映射更新了我的问题