通过“_id”查找文档时Id的查询和Term查询有什么区别?
What's the difference between Id's query and Term Query when finding documents by "_id"?
我想通过“_id”获取文档,我有3个选择:
GET document by "_id" GET order/_doc/001
Use Id's Query, GET order/_search { "query": { "ids" : { "values" : ["001"] } } } Though Id's query takes array of Id's but I will be using it to get only one document at a time, so just passing one id in "values" : ["001"]
Use Term Query GET order/_search { "query": {"term": {"_id" : "001"}}}
我想知道 Id 的查询和 Term 查询在性能方面有什么区别以及我应该注意的任何其他要点?
我应该选择哪一个(在 Id 和 Term 查询之间)?
非常感谢任何帮助:)
第一个选项不是搜索,只是通过 id 获取文档。
如果您查看第二个和第三个查询的执行计划,您会发现它们是相同的:
Ids查询:
GET order/_search
{
"explain": true,
"query": {
"ids": {
"values": ["001"]
}
}
}
执行计划:
"_explanation" : {
"value" : 1.0,
"description" : "sum of:",
"details" : [
{
"value" : 1.0,
"description" : "ConstantScore(_id:[fe 0 1f])",
"details" : [ ]
},
{
"value" : 0.0,
"description" : "match on required clause, product of:",
"details" : [
{
"value" : 0.0,
"description" : "# clause",
"details" : [ ]
},
{
"value" : 1.0,
"description" : "DocValuesFieldExistsQuery [field=_primary_term]",
"details" : [ ]
}
]
}
]
}
词条查询:
GET order/_search
{
"explain": true,
"query": {
"term": {
"_id": "001"
}
}
}
执行计划:
"_explanation" : {
"value" : 1.0,
"description" : "sum of:",
"details" : [
{
"value" : 1.0,
"description" : "ConstantScore(_id:[fe 0 1f])",
"details" : [ ]
},
{
"value" : 0.0,
"description" : "match on required clause, product of:",
"details" : [
{
"value" : 0.0,
"description" : "# clause",
"details" : [ ]
},
{
"value" : 1.0,
"description" : "DocValuesFieldExistsQuery [field=_primary_term]",
"details" : [ ]
}
]
}
]
}
有什么不同吗? None!
我想通过“_id”获取文档,我有3个选择:
GET document by "_id" GET order/_doc/001
Use Id's Query, GET order/_search { "query": { "ids" : { "values" : ["001"] } } } Though Id's query takes array of Id's but I will be using it to get only one document at a time, so just passing one id in "values" : ["001"]
Use Term Query GET order/_search { "query": {"term": {"_id" : "001"}}}
我想知道 Id 的查询和 Term 查询在性能方面有什么区别以及我应该注意的任何其他要点?
我应该选择哪一个(在 Id 和 Term 查询之间)?
非常感谢任何帮助:)
第一个选项不是搜索,只是通过 id 获取文档。
如果您查看第二个和第三个查询的执行计划,您会发现它们是相同的:
Ids查询:
GET order/_search
{
"explain": true,
"query": {
"ids": {
"values": ["001"]
}
}
}
执行计划:
"_explanation" : {
"value" : 1.0,
"description" : "sum of:",
"details" : [
{
"value" : 1.0,
"description" : "ConstantScore(_id:[fe 0 1f])",
"details" : [ ]
},
{
"value" : 0.0,
"description" : "match on required clause, product of:",
"details" : [
{
"value" : 0.0,
"description" : "# clause",
"details" : [ ]
},
{
"value" : 1.0,
"description" : "DocValuesFieldExistsQuery [field=_primary_term]",
"details" : [ ]
}
]
}
]
}
词条查询:
GET order/_search
{
"explain": true,
"query": {
"term": {
"_id": "001"
}
}
}
执行计划:
"_explanation" : {
"value" : 1.0,
"description" : "sum of:",
"details" : [
{
"value" : 1.0,
"description" : "ConstantScore(_id:[fe 0 1f])",
"details" : [ ]
},
{
"value" : 0.0,
"description" : "match on required clause, product of:",
"details" : [
{
"value" : 0.0,
"description" : "# clause",
"details" : [ ]
},
{
"value" : 1.0,
"description" : "DocValuesFieldExistsQuery [field=_primary_term]",
"details" : [ ]
}
]
}
]
}
有什么不同吗? None!