【问题标题】:How to set include_type_name in postman to true如何将邮递员中的 include_type_name 设置为 true
【发布时间】:2019-09-06 02:58:37
【问题描述】:

我正在邮递员中创建映射索引,但出现以下错误。 我正在尝试创建一个索引,该索引将使用我创建的 index.js 函数与我的弹性搜索 firebase 服务器进行通信。可能是什么问题?

这是我的代码

"mappings":{
        "properties":{
                "city":{
                    "type": "text"
                },
                "contact_email":{
                    "type": "text"
                },
                "country":{
                    "type": "text"
                },
                "description":{
                "type": "text"
                },
                "image":{
                "type": "text"
                },
                "post_id":{
                    "type": "text"
                },
                "state_province":{
                    "type": "text"
                },
                "title":{
                    "type": "text"
                }
            }
        }
    }

这里是 index.js 函数的代码

const functions = require('firebase-functions');

const request = require('request-promise')

exports.indexPostsToElastic = functions.database.ref('/posts/{post_id}')
        .onWrite((change,context) =>{
        let postData = change.after.val();
        let post_id = context.params.post_id;

        console.log('Indexing post',postData);

        let elasticSearchConfig = functions.config().elasticsearch;


        let elasticSearchUrl = elasticSearchConfig.url + 'posts/' + post_id;
        let elasticSearchMethod = postData ? 'POST' : 'DELETE';

        let elasticSearchRequest = {
            method:elasticSearchMethod,
                url: elasticSearchUrl,
                auth:{
                    username : elasticSearchConfig.username,
                    password : elasticSearchConfig.password,
                },
                body: postData,
                json : true
              };
              return request(elasticSearchRequest).then(response => {
                  console.log("ElasticSearch response", response);
                  return response;
              });
            });

我在 firebase 中收到以下错误

StatusCodeError: 400 - {"error":{"root_cause":[{"type":"illegal_argument_exception","reason":"Rejecting mapping update to [posts] as the final mapping would have more than 1 type: [_doc, -LcajBAxUn3jrq0EHzYa]"}],

这是我在 firebase 中的数据库示例

-LcajBAxUn3jrq0EHzYa

city:

contact_email:

country:

description:

image:

post_id:

price:

state_province:

title: 

请帮助我确定我的错误可能在哪里。

【问题讨论】:

  • 你能在这里提供更多细节吗?这是否是请求正文的一部分?服务器代码是什么?你到底想达到什么目的?请提供更多背景信息,以便其他人能够理解您的问题并为您提供帮助。
  • 你找到解决办法了吗?

标签: node.js firebase elasticsearch postman


【解决方案1】:

include_type_name 是最近几个版本中引入的弹性搜索标志。见背景here。它的目标是解决elasticsearch type != tableName 的长期困惑。要在您的请求中包含include_type_name,请参阅this。

这更像是一个 Elasticsearch API 问题,而不是 firebase / postman。

【讨论】:

    【解决方案2】:

    您首先需要检查您使用的 elasticSearch 版本。 如果您使用的版本低于 7.0,那么您必须在“_doc”字段中输入您的属性标签。 “_doc”字段稍后在高于 7.0 的 elasticSearch 版本中被取代。下面是改版后的映射。

    "mappings":{
        "_doc" :{
        "properties":{
                "city":{
                    "type": "text"
                },
                "contact_email":{
                    "type": "text"
                },
                "country":{
                    "type": "text"
                },
                "description":{
                "type": "text"
                },
                "image":{
                "type": "text"
                },
                "post_id":{
                    "type": "text"
                },
                "state_province":{
                    "type": "text"
                },
                "title":{
                    "type": "text"
                }
            }
        }
       }
    }
    

    【讨论】:

      猜你喜欢
      • 2019-12-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-04-03
      • 1970-01-01
      • 2021-07-08
      • 2023-01-30
      • 2020-02-26
      相关资源
      最近更新 更多