在每个要编制索引的文档中,我都有一个称为“永久链接”的字段,我想对其进行精确匹配。
示例文件:
{
"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/