匹配类型的 DSL 查询如何不起作用?
How DSL query for match type is not working?
数据集如下
PUT /dataall/test/1
{
"name": "Computer Science 101",
"room": "C12",
"professor": {
"name": "Gregg Payne",
"department": "engineering",
"facutly_type": "full-time",
"email": "payneg@onuni.com"
},
"students_enrolled": 33,
"course_publish_date": "2013-08-27",
"course_description": "CS 101 is a first year computer science introduction teaching fundamental data structures and alogirthms using python. "
}
PUT /dataall/test/2
{
"name": "Theatre 410",
"room": "T18",
"professor": {
"name": "Greg",
"department": "art",
"facutly_type": "part-time",
"email": ""
},
"students_enrolled": 47,
"course_publish_date": "2013-01-27",
"course_description": "Tht 410 is an advanced elective course disecting the various plays written by shakespere during the 16th century"
}
下面是DSL查询
GET dataall/_search
{
"query": {
"match": {
"professor.name":"Greg"
}
}
}
映射如下。教授在嵌套 json
{
"dataall" : {
"mappings" : {
"properties" : {
"course_description" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
},
"course_publish_date" : {
"type" : "date"
},
"dataproduct" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
},
"id" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
},
"name" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
},
"professor" : {
"properties" : {
"department" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
},
"email" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
},
"facutly_type" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
},
"name" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
}
}
},
"room" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
},
"students_enrolled" : {
"type" : "long"
}
}
}
}
}
预计是 2(因为“Greg”与 Gregg Payne 相似)但我得到的是第二份文件,完全匹配?
为什么我的查询不起作用?甚至 match_phrase_prefix.
也是强制性的
我的其他索引工作正常,是因为映射嵌套吗json?
由于您没有提供数据映射,因此可能有两种可能性,即您的 professor
字段是嵌套数据类型或对象数据类型
考虑到您已经为 professor
字段创建了 嵌套数据类型 。
要了解有关 Match Phrase 前缀查询的更多信息,请参阅此 ES documentation
映射:
{
"mappings": {
"properties": {
"name": {
"type": "text"
},
"room": {
"type": "text"
},
"professor": {
"type": "nested",
"properties": {
"name": {
"type": "text"
}
}
}
}
}
}
搜索查询:
{
"query":{
"nested":{
"path":"professor",
"query":{
"match_phrase_prefix":{
"professor.name":"Greg"
}
}
}
}
}
现在,考虑到文档包含一个 内部对象 professor
。要了解有关对象数据类型的更多信息,请参阅 this
映射:
{
"mappings": {
"properties": {
"name": {
"type": "text"
},
"professor": {
"properties": {
"name": { "type": "text" }
}
}
}
}
}
搜索查询:
{
"query": {
"match_phrase_prefix": {
"professor.name": "Greg"
}
}
}
以上搜索 returns 个包含 professor
的 name
字段中以 Greg
开头的短语的文档。想了解更多关于匹配词组前缀查询可以参考this
数据集如下
PUT /dataall/test/1
{
"name": "Computer Science 101",
"room": "C12",
"professor": {
"name": "Gregg Payne",
"department": "engineering",
"facutly_type": "full-time",
"email": "payneg@onuni.com"
},
"students_enrolled": 33,
"course_publish_date": "2013-08-27",
"course_description": "CS 101 is a first year computer science introduction teaching fundamental data structures and alogirthms using python. "
}
PUT /dataall/test/2
{
"name": "Theatre 410",
"room": "T18",
"professor": {
"name": "Greg",
"department": "art",
"facutly_type": "part-time",
"email": ""
},
"students_enrolled": 47,
"course_publish_date": "2013-01-27",
"course_description": "Tht 410 is an advanced elective course disecting the various plays written by shakespere during the 16th century"
}
下面是DSL查询
GET dataall/_search
{
"query": {
"match": {
"professor.name":"Greg"
}
}
}
映射如下。教授在嵌套 json
{
"dataall" : {
"mappings" : {
"properties" : {
"course_description" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
},
"course_publish_date" : {
"type" : "date"
},
"dataproduct" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
},
"id" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
},
"name" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
},
"professor" : {
"properties" : {
"department" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
},
"email" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
},
"facutly_type" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
},
"name" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
}
}
},
"room" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
},
"students_enrolled" : {
"type" : "long"
}
}
}
}
}
预计是 2(因为“Greg”与 Gregg Payne 相似)但我得到的是第二份文件,完全匹配?
为什么我的查询不起作用?甚至 match_phrase_prefix.
也是强制性的我的其他索引工作正常,是因为映射嵌套吗json?
由于您没有提供数据映射,因此可能有两种可能性,即您的 professor
字段是嵌套数据类型或对象数据类型
考虑到您已经为 professor
字段创建了 嵌套数据类型 。
要了解有关 Match Phrase 前缀查询的更多信息,请参阅此 ES documentation
映射:
{
"mappings": {
"properties": {
"name": {
"type": "text"
},
"room": {
"type": "text"
},
"professor": {
"type": "nested",
"properties": {
"name": {
"type": "text"
}
}
}
}
}
}
搜索查询:
{
"query":{
"nested":{
"path":"professor",
"query":{
"match_phrase_prefix":{
"professor.name":"Greg"
}
}
}
}
}
现在,考虑到文档包含一个 内部对象 professor
。要了解有关对象数据类型的更多信息,请参阅 this
映射:
{
"mappings": {
"properties": {
"name": {
"type": "text"
},
"professor": {
"properties": {
"name": { "type": "text" }
}
}
}
}
}
搜索查询:
{
"query": {
"match_phrase_prefix": {
"professor.name": "Greg"
}
}
}
以上搜索 returns 个包含 professor
的 name
字段中以 Greg
开头的短语的文档。想了解更多关于匹配词组前缀查询可以参考this