Elasticsearch:路径下的嵌套对象不是嵌套类型 [英] Elasticsearch: nested object under path is not of nested type
问题描述
我一直在尝试搜索包含嵌套字段的文档。我创建了这样的嵌套映射:
{
message:{
properties {
message:{
type:nested,
properties:{
message_id:{type:string},
message_text:{type:string},
message_nick:{type:string}
}
}
}
}
}
我的搜索如下所示:
curl -XGET'localhost:9200 / thread_and_messages / thread / _search'\
-d'{query:{bool :{必须:{匹配:{thread_name:香蕉}},{嵌套:{路径:消息,查询:{bool :[{match:{messages.message_text:Banana}}]}}}}}}}}'
但是我收到此错误消息:
QueryParsingException [[thread_and_messages] [嵌套]嵌套对象under path [messages]不是嵌套类型]
编辑
我仍然收到此错误。我通过Java这样做,所以这是我要创建的文档:
{
_id: {
path:3,
thread_id:3,
thread_name:Banana,
created:Wed Mar 25 2015 ,
first_nick:AdminTech,
messages:[
{
message_id:9,
message_text:香蕉,
message_nick:AdminTech
}
]
}
}
如下创建索引:
CreateIndexRequestBuilder indexRequest = client.admin() .indices()。prepareCreate(INDEX).addMapping(message,mapping);
我认为我可能会错误地索引文档。
TLDR:在您的嵌套类型中放入type:nested,
{
some_index:{
mappings:{
normal_type:{
properties:{
nested_type:{
type nested,
properties:{
address:{
type:string
},
country:{
type:string
}
}
},
first_name:{
type:string
} ,
last_name:{
type:string
}
}
}
}
}
}
嵌套查询工作所需的类型:嵌套行是
path:
分配给 nested_type
,如下所示:
GET / some_index / normal_type / _search
{
查询:{
嵌套:{
查询:{
bool:{}
},
path:nested_type
}
}
}
仅在较新的Elasticsearch版本(自1.1.1?起)以来,type:nested,
/ p>
I've been trying to search on my document which contains a nested field. I created the nested mapping like this:
{
"message": {
"properties": {
"messages": {
"type": "nested",
"properties": {
"message_id": { "type": "string" },
"message_text": { "type": "string" },
"message_nick": { "type": "string" }
}
}
}
}
}
My search looks like this:
curl -XGET 'localhost:9200/thread_and_messages/thread/_search' \
-d '{"query": {"bool": {"must": [{"match": {"thread_name": "Banana"}}, {"nested": {"path": "messages", "query": {"bool": {"must": [{"match": {"messages.message_text": "Banana"}}]}}}]}}}}'
Yet I am receiving this error message:
QueryParsingException[[thread_and_messages] [nested] nested object under path [messages] is not of nested type]
EDIT
I am still receiving this error. I am doing this via Java so this is the document I am trying to create:
{
"_id": {
"path": "3",
"thread_id": "3",
"thread_name": "Banana",
"created": "Wed Mar 25 2015",
"first_nick": "AdminTech",
"messages": [
{
"message_id": "9",
"message_text": "Banana",
"message_nick": "AdminTech"
}
]
}
}
Creating the index like so:
CreateIndexRequestBuilder indexRequest = client.admin().indices().prepareCreate(INDEX).addMapping("message", mapping);
I think I am possibly indexing the document incorrectly.
TLDR: Put "type": "nested",
in your nested type.
Say we have a normal type, and another type nested in it:
{
"some_index": {
"mappings": {
"normal_type": {
"properties": {
"nested_type": {
"type": "nested",
"properties": {
"address": {
"type": "string"
},
"country": {
"type": "string"
}
}
},
"first_name": {
"type": "string"
},
"last_name": {
"type": "string"
}
}
}
}
}
}
The "type": "nested",
line is required for the nested queries to work which have "path":
assigned to nested_type
, like this:
GET /some_index/normal_type/_search
{
"query": {
"nested": {
"query": {
"bool": {}
},
"path": "nested_type"
}
}
}
The "type": "nested",
line seems to be required in newer Elasticsearch versions only (since 1.1.1 ?).
这篇关于Elasticsearch:路径下的嵌套对象不是嵌套类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!