我正在使用Elasticsearch v1.5.2。我有一个类似于以下内容的JSON文档。
{
"id": "RRRZe32",
"metadata": {
"published": "2010-07-29T18:11:43.000Z",
"codeId": "AChdUxnsuRyoCo7roK6gqZSg",
"codeTitle": "something"
}
}
备份此JSON的我的Java POJO对象如下所示。请注意,我使用的Spring-Boot v1.3.0.M2具有spring-boot-starter-data-elasticsearch
依赖性。
@Document(indexName="ws", type="vid")
public class Video {
@Id
private String id;
@Field(type=FieldType.Object, index=FieldIndex.not_analyzed)
private Map<String, Object> metadata;
}
我的映射定义如下。
{
"ws": {
"mappings": {
"vid": {
"properties": {
"id": {
"type": "string"
},
"metadata": {
"properties": {
"codeId": {
"type": "string"
},
"codeTitle": {
"type": "string"
}
}
}
}
}
}
}
}
我可以Sense
成功查询文档(使用metadata.codeTitle
),但不能metadata.codeId
。我对metadata.codeTitle
的查询如下所示。
{
"query": {
"bool": {
"must": [
{
"term": {
"metadata.codeTitle": {
"value": "something"
}
}
}
]
}
}
}
我对metadata.codeId
的查询如下所示。
{
"query": {
"bool": {
"must": [
{
"term": {
"metadata.codeId": {
"value": "AChdUxnsuRyoCo7roK6gqZSg"
}
}
}
]
}
}
}
关于我做错的任何想法?
答案 0 :(得分:1)
这是因为您的codeId
字段为analyzed
,并且在索引编制时该值较低。所以你有两个解决方案:
您可以像这样查询(即全小写)
{
"query": {
"bool": {
"must": [
{
"term": {
"metadata.codeId": {
"value": "achduxnsuryoco7rok6gqzsg"
}
}
}
]
}
}
}
或者您可以将codeId
字段声明为not_analyzed
,并保持您的查询不变。
在您的情况下,看起来案例1将更容易实施。