Saya ingin menemukan dokumen yang memiliki preices.info yang diajukan sama dengan nol. Harga adalah file bersarang Contoh kueri terlihat seperti ini

    {
    "query": {
        "bool": {
            "must": [
                {
                    "term": {
                        "doc_type": "supnom"
                    }
                },
                {
                    "term": {
                        "is_linking_disabled": false
                    }
                },
                {
                    "has_parent": {
                        "parent_type": "sup",
                        "query": {
                            "bool": {
                                "must": [
                                    {
                                        "term": {
                                            "id": 89634082
                                        }
                                    }
                                ]
                            }
                        }
                    }
                },
                {
                    "bool": {
                        "should": [
                            {
                                "bool": {
                                    "must": [
                                        {
                                            "term": {
                                                "folder_type": 0
                                            }
                                        },
                                        {
                                            "term": {
                                                "folder": "NULL"
                                            }
                                        },
                                        {
                                            "term": {
                                                "is_folder": true
                                            }
                                        },
                                        {
                                            "term": {
                                                "is_folder_hybrid": true
                                            }
                                        }
                                    ]
                                }
                            },
                            {
                                "bool": {
                                    "must": [
                                        {
                                            "term": {
                                                "folder_type": 1
                                            }
                                        },
                                        {
                                            "term": {
                                                "folder": "89634082-NULL"
                                            }
                                        },
                                        {
                                            "term": {
                                                "is_folder": true
                                            }
                                        },
                                        {
                                            "term": {
                                                "is_folder_hybrid": true
                                            }
                                        }
                                    ]
                                }
                            },
                            {
                                "bool": {
                                    "must": [
                                        {
                                            "term": {
                                                "is_folder": false
                                            }
                                        },
                                        {
                                            "term": {
                                                "folder_hybrid": "NULL"
                                            }
                                        },
                                        {
                                            "nested": {
                                                "path": "prices",
                                                "query": {
                                                    "terms": {
                                                        "prices.id_prcknd": [
                                                            22215
                                                        ]
                                                    }
                                                }
                                            }
                                        }
                                    ]
                                }
                            },
                            {
                                "bool": {
                                    "must_not": [
                                        {
                                            "nested": {
                                                "path": "prices",
                                                "query": {
                                                    "bool": {
                                                        "filter": {
                                                            "exists": {
                                                                "field": "prices.info"
                                                            }
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                    ]
                                }
                            }
                        ]
                    }
                }
            ],
            "must_not": [],
            "should": []
        }
    },
    "size": 70,
    "from": 0,
    "_source": true,
    "sort": [
        {
            "is_folder": {
                "order": "desc"
            }
        },
        {
            "title_low.order": {
                "order": "asc"
            }
        }
    ]
}

Lagi pula saya mendapatkan dokumen hasil dengan bidang NOT null prices.info

{
"took": 65,
"timed_out": false,
"_shards": {
    "total": 1,
    "successful": 1,
    "skipped": 0,
    "failed": 0
},
"hits": {
    "total": 7,
    "max_score": null,
    "hits": [
        {
            "_index": "supnoms",
            "_type": "doc",
            "_id": "supnom-108340976",
            "_score": null,
            "_routing": "1",
            "_source": {
                "codes": null,
                "folder": null,
                "folder_hybrid": null,
                "folder_hybrid_type": 0,
                "folder_type": null,
                "id": "108340976",
                "id_supplier": 89634082,
                "is_folder": false,
                "is_folder_hybrid": null,
                "is_linking_disabled": false,
                "manufacturer": {
                    "id": null,
                    "title": null
                },
                "market_nom": {
                    "folder": null,
                    "id": null
                },
                "path_market": {
                    "parents": null,
                    "pids": null,
                    "strpath": null
                },
                "path_supnom": {
                    "parents": null,
                    "pids": null,
                    "strpath": null
                },
                "prices": [
                    {
                        "currency": "RUR",
                        "id_offer": 605966502,
                        "id_prcdoc": 42040,
                        "id_prcknd": 22215,
                        "info": {
                            "Price": "По запросу"
                        },
                        "min_order": null,
                        "sell_by": null,
                        "value": "По запросу"
                    }
                ],
                "sup_code": "c39f81c9-1a69-3a7d-9e04-5f4e124242e7",
                "title": "баклажан UPC",
                "title_low": "баклажан upc",
                "_join_field_name": "doc_type",
                "doc_type": {
                    "name": "supnom",
                    "parent": "sup-89634082"
                }
            },
            "sort": [
                0,
                "баклажан upc"
            ]
        },
        {
            "_index": "supnoms",
            "_type": "doc",
            "_id": "supnom-108340975",
            "_score": null,
            "_routing": "1",
            "_source": {
                "codes": null,
                "folder": null,
                "folder_hybrid": null,
                "folder_hybrid_type": 0,
                "folder_type": null,
                "id": "108340975",
                "id_supplier": 89634082,
                "is_folder": false,
                "is_folder_hybrid": null,
                "is_linking_disabled": false,
                "manufacturer": {
                    "id": null,
                    "title": null
                },
                "market_nom": {
                    "folder": null,
                    "id": null
                },
                "path_market": {
                    "parents": null,
                    "pids": null,
                    "strpath": null
                },
                "path_supnom": {
                    "parents": null,
                    "pids": null,
                    "strpath": null
                },
                "prices": [
                    {
                        "currency": "RUR",
                        "id_offer": 605966498,
                        "id_prcdoc": 42040,
                        "id_prcknd": 22215,
                        "info": {},
                        "min_order": null,
                        "sell_by": null,
                        "value": "10.00"
                    }
                ],
                "sup_code": "8be655dc-0873-3dfc-994b-602b2e4e0799",
                "title": "Избранные для дубля без цены",
                "title_low": "избранные для дубля без цены",
                "_join_field_name": "doc_type",
                "doc_type": {
                    "name": "supnom",
                    "parent": "sup-89634082"
                }
            },
            "sort": [
                0,
                "избранные для дубля без цены"
            ]
        },
        {
            "_index": "supnoms",
            "_type": "doc",
            "_id": "supnom-108340974",
            "_score": null,
            "_routing": "1",
            "_source": {
                "codes": null,
                "folder": null,
                "folder_hybrid": null,
                "folder_hybrid_type": 0,
                "folder_type": null,
                "id": "108340974",
                "id_supplier": 89634082,
                "is_folder": false,
                "is_folder_hybrid": null,
                "is_linking_disabled": false,
                "manufacturer": {
                    "id": null,
                    "title": null
                },
                "market_nom": {
                    "folder": null,
                    "id": null
                },
                "path_market": {
                    "parents": null,
                    "pids": null,
                    "strpath": null
                },
                "path_supnom": {
                    "parents": null,
                    "pids": null,
                    "strpath": null
                },
                "prices": [
                    {
                        "currency": "RUR",
                        "id_offer": 605966500,
                        "id_prcdoc": 42040,
                        "id_prcknd": 22215,
                        "info": {},
                        "min_order": null,
                        "sell_by": null,
                        "value": "10.00"
                    }
                ],
                "sup_code": "867f138d-d8cc-37e7-b1b2-f07a4627ba49",
                "title": "Избранные для дубля с ценой",
                "title_low": "избранные для дубля с ценой",
                "_join_field_name": "doc_type",
                "doc_type": {
                    "name": "supnom",
                    "parent": "sup-89634082"
                }
            }

Bidang harga dalam indeks terlihat seperti ini "harga": { "type": "nested", "properties": { "currency": { "type": "keyword" }, "id_offer": { "type": "integer " }, "id_prcdoc": { "type": "integer" }, "id_prcknd": { "type": "integer" }, "min_order": { "type": "keyword" }, "sell_by": { "type": "keyword" }, "value": { "type": "keyword", "index": false } } }

0
Alex Nikitin 6 Maret 2020, 13:56

1 menjawab

Jawaban Terbaik

Melihat dari kueri yang Anda miliki, Anda ingin melihat semua dokumen yang tidak memiliki nilai prices.info.

Cukup pindahkan bagian must_not yang Anda miliki ke tingkat pertama dalam kueri bool yang Anda miliki. Silakan lihat di bawah ini untuk lebih jelas:

Pertanyaan Asli:

{
  "query": {
    "bool": {
      "must": [
        { term }
        { term }
        { hasparent }
        { bool 
          - should 
             - must
             - must
             - must
             - must_not         <---- Remove this 
                - { exists }    <---- Copy this
        }
      ],
      "must_not": [],           <---- And add that here
      "should": [
        {}
      ]
    }
  }
}

Solusi Kode Psuedo:

{
  "query": {
    "bool": {
      "must": [
        { term }
        { term }
        { hasparent }
        { bool 
          - should 
             - must
             - must
             - must
        }
      ],
      "must_not": [
        { exists }     <--- Note this    
      ],
      "should": [
        {}
      ]
    }
  }
}

DSL kueri

Di bawah ini adalah kueri yang Anda cari:

{
   "query":{
      "bool":{
         "must":[
            {
               "term":{
                  "doc_type":"supnom"
               }
            },
            {
               "term":{
                  "is_linking_disabled":false
               }
            },
            {
               "has_parent":{
                  "parent_type":"sup",
                  "query":{
                     "bool":{
                        "must":[
                           {
                              "term":{
                                 "id":89634082
                              }
                           }
                        ]
                     }
                  }
               }
            },
            {
               "bool":{
                  "should":[
                     {
                        "bool":{
                           "must":[
                              {
                                 "term":{
                                    "folder_type":0
                                 }
                              },
                              {
                                 "term":{
                                    "folder":"NULL"
                                 }
                              },
                              {
                                 "term":{
                                    "is_folder":true
                                 }
                              },
                              {
                                 "term":{
                                    "is_folder_hybrid":true
                                 }
                              }
                           ]
                        }
                     },
                     {
                        "bool":{
                           "must":[
                              {
                                 "term":{
                                    "folder_type":1
                                 }
                              },
                              {
                                 "term":{
                                    "folder":"89634082-NULL"
                                 }
                              },
                              {
                                 "term":{
                                    "is_folder":true
                                 }
                              },
                              {
                                 "term":{
                                    "is_folder_hybrid":true
                                 }
                              }
                           ]
                        }
                     },
                     {
                        "bool":{
                           "must":[
                              {
                                 "term":{
                                    "is_folder":false
                                 }
                              },
                              {
                                 "term":{
                                    "folder_hybrid":"NULL"
                                 }
                              },
                              {
                                 "nested":{
                                    "path":"prices",
                                    "query":{
                                       "terms":{
                                          "prices.id_prcknd":[
                                             22215
                                          ]
                                       }
                                    }
                                 }
                              }
                           ]
                        }
                     }
                  ]
               }
            }
         ],
         "must_not":[
            {
               "nested":{
                  "path":"prices",
                  "query":{
                     "exists":{
                        "field":"prices.info"
                     }
                  }
               }
            }
         ],
         "should":[

         ]
      }
   },
   "size":70,
   "from":0,
   "_source":true,
   "sort":[
      {
         "is_folder":{
            "order":"desc"
         }
      },
      {
         "title_low.order":{
            "order":"asc"
         }
      }
   ]
}

Perhatikan bahwa Anda seharusnya tidak melihat dokumen apa pun yang memiliki bidang prices.info. Perhatikan juga bahwa saya telah menyederhanakan kueri agar tetap sederhana.

Beri tahu saya jika ini berhasil!

1
Opster ES Ninja - Kamal 6 Maret 2020, 19:42