elasticsearch - 与Elasticsearch中的字段完全匹配

标签 elasticsearch

在每个要编制索引的文档中,我都有一个称为“永久链接”的字段,我想对其进行精确匹配。

示例文件:

{
    "entity_type": "company",
    "entity_id": 1383221763,
    "company_type": "developer",
    "name": "Runewaker Entertainment",
    "permalink": "runewaker-entertainment"
}

这些文档的映射为:
{
    "properties": {
        "entity_id": {
            "type": "integer",
            "include_in_all": false
        },
        "name": {
            "type": "string",
            "include_in_all": true,
        },
        "permalink": {
            "type": "string",
            "include_in_all": true,
            "index": "not_analyzed"
        },
        "company_type": {
            "type": "string",
            "include_in_all": false,
            "index": "not_analyzed"
        }
    }
}

当我运行以下查询时,我没有得到任何点击:
POST /companies/company/_search HTTP/1.1
Host: localhost:8082

{
    "query": {
        "filtered": {
            "query": {
                "match_all": {}
            },
            "filter": {
                "term": { "permalink": "runewaker-entertainment" }
            }
        }
    }
}

但我得到与此查询匹配:
POST /companies/company/_search HTTP/1.1
Host: localhost:8082

{
    "query": {
        "filtered": {
            "query": {
                "match_all": {}
            },
            "filter": {
                "term": { "permalink": "runewaker" }
            }
        }
    }
}

似乎任何带有连字符的永久链接都会导致查询失败,但我的印象是,如果属性的映射将索引设置为not_analyzed,则ElasticSearch根本不会分析该字段。

正确的查询应该是什么?

谢谢

更新:

公司索引上的getMapping结果:
{
  "companies" : {
    "company" : {
      "properties" : {
        "company_type" : {
          "type" : "string"
        },
        "entity_id" : {
          "type" : "long"
        },
        "entity_type" : {
          "type" : "string"
        },
        "name" : {
          "type" : "string"
        },
        "node_id" : {
          "type" : "long"
        },
        "permalink" : {
          "type" : "string"
        }
      }
    }
  }
}

最佳答案

您所描述的是正确的。

我测试了,它按预期工作。因此,您的索引可能有问题。也许您在设置映射之前先索引了文档?
再次尝试-
删除您的索引或创建一个新索引。
对您的映射执行putMapping。
为文档编制索引。

搜索应按预期工作。

关于elasticsearch - 与Elasticsearch中的字段完全匹配,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19709155/

相关文章:

elasticsearch - Solr 6 中没有的 Elasticsearch 5 中的性能特性

elasticsearch - Elasticsearch [5.4]通过句子中的单词位置评分

elasticsearch - "Mapping conflict!"Kibana 错误

elasticsearch - 如何在Elasticsearch中的SQL中获得简单的查询多匹配文本?

amazon-web-services - 基于位置的AWS AppSync事件订阅

azure - Azure VM 上具有多个节点的集群上的 Elasticsearch 所有分片均失败

json - 字符串的Elasticsearch类型对象

elasticsearch - 戈朗错误 "not enough arguments in call"

elasticsearch - 如何聚合 Elasticsearch 中的动态字段?

elasticsearch - ElasticSearch NEST API 中的滚动示例