我有这种格式在elasticsearch的数据的条件下,每一个都是单独的文件中:ElasticSearch查询与多个文档
{“PID”:1“纳米”:“汤姆”},{“PID” :1,'nm':'dick''},{'pid':1,'nm':'harry'},{'pid':2,'nm':'tom'},{'pid': 2,'nm':'harry'},{'pid':3,'nm':'dick'},{'pid':3,'nm':'harry'},{'pid':4, “纳米”:“哈利”}
{
"took": 137,
"timed_out": false,
"_shards": {
"total": 5,
"successful": 5,
"failed": 0
},
"hits": {
"total": 8,
"max_score": null,
"hits": [
{
"_index": "query_test",
"_type": "user",
"_id": "AVj9KS86AaDUbQTYUmwY",
"_score": null,
"_source": {
"pid": 1,
"nm": "Harry"
}
},
{
"_index": "query_test",
"_type": "user",
"_id": "AVj9KJ9BAaDUbQTYUmwW",
"_score": null,
"_source": {
"pid": 1,
"nm": "Tom"
}
},
{
"_index": "query_test",
"_type": "user",
"_id": "AVj9KRlbAaDUbQTYUmwX",
"_score": null,
"_source": {
"pid": 1,
"nm": "Dick"
}
},
{
"_index": "query_test",
"_type": "user",
"_id": "AVj9KYnKAaDUbQTYUmwa",
"_score": null,
"_source": {
"pid": 2,
"nm": "Harry"
}
},
{
"_index": "query_test",
"_type": "user",
"_id": "AVj9KXL5AaDUbQTYUmwZ",
"_score": null,
"_source": {
"pid": 2,
"nm": "Tom"
}
},
{
"_index": "query_test",
"_type": "user",
"_id": "AVj9KbcpAaDUbQTYUmwb",
"_score": null,
"_source": {
"pid": 3,
"nm": "Dick"
}
},
{
"_index": "query_test",
"_type": "user",
"_id": "AVj9Kdy5AaDUbQTYUmwc",
"_score": null,
"_source": {
"pid": 3,
"nm": "Harry"
}
},
{
"_index": "query_test",
"_type": "user",
"_id": "AVj9KetLAaDUbQTYUmwd",
"_score": null,
"_source": {
"pid": 4,
"nm": "Harry"
}
}
]
}
}
,我需要找到PID的具有“哈利”和没有“汤姆”,这在上面的例子中是3和4这essentialy意味着寻找具有相同pid的文档,其中没有任何一个具有nm的值“汤姆“,但他们中至少有一个的价值为'哈里'。
如何查询?
编辑:使用Elasticsearch版本5
在分析的字段上使用术语查询不危险吗?如果没有提供映射,nm将在这种情况下被分析。 – Artholl
@Artholl如果您使用'not_analyzed',如果您不希望为上述场景分析该字段,该怎么办? – Kulasangar
@Kulasangar不会在同一个文档上应用匹配/过滤条件吗?但是,例如,在这里,三个文档具有相同的pid,即1,但是'nm'有三个不同的值。 – harbinger