最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

Elasticsearch错误:[parsing

运维笔记admin15浏览0评论

Elasticsearch错误:[parsing

Elasticsearch错误:[parsing

我遇到了elasticsearch npm模块的问题。这是我的查询:

try {
    const {
        hits: { hits }
    } = await client.search({
        index: "articles",
        body: {
            query: {
                match_phrase: {
                    authors: {
                        first_name: firstName,
                        last_name: lastName
                    }
                }
            }
        }
    });

    hits.forEach(hit => {
        hit.type = TYPE_PHRASE;
    });

    return hits;
} catch (err) {

但是这将返回错误,

Error: [parsing_exception] [match_phrase] query does not support [first_name]

我不确定这是什么意思。这是否意味着我无法通过first_name进行搜索?

这是elasticsearch结构:

 [
      {
           "_score": 10.8702135,
           "_source": {
                "title": "Some title",
                "authors": [
                     {
                          "first_name": "John",
                          "last_name": "Smith",
                     },
                     {
                          "first_name": "Jane",
                          "last_name": "Doe",
                     },
回答如下:

Match_phrase适用于单个字段。要搜索多个字段,请使用must / bool子句组合多个match_phrase子句。

query: {
          bool: {
                     must: [
                               {
                                   match_phrase: {
                                                   authors.first_name: firstName
                                                 }                  
                                },
                                {
                                   match_phrase: {
                                                   authors.last_name: lastName
                                                 }                  
                                },
                            ]
                 }                
            }

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论