Applying match_phrase and filter












1















Worked on Elastic Search 6.4.2. I want to use match_pharseto get the retrieve the results from my index. In the same way I need to apply the filter for that. Any solution for this. I tried the below query



{
"query": {
"bool": {
"should":
{
"match_phrase": {
"title": "bike riding"
}}

}
}}


But When I using match_pharse I need to pass the fields in order to get the results. I am sharing my mapping and query that I need to be edited. Any help that I can use the match_phrase for a query.



Mapping:



{
"mapping": {
"doc": {
"properties": {
"content": {
"type": "text",
"store": true,
"analyzer": "my_analyzer"
},
"description": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"domain": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"host": {
"type": "keyword",
"store": true
},
"keywords": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"seed": {
"type": "keyword",
"store": true
},
"title": {
"type": "text",
"store": true,
"analyzer": "my_analyzer"
},
"url": {
"type": "text",
"store": true
}
}
}
}
}`


Query:
How can I add match_phrase to the below one



{
"query": {
"bool" : {
"must" : {
"query_string" : {
"query" : "bike riding"
}
},
"filter" : {
"term" : { "seed" : "sports" }
}
}
}
}









share|improve this question



























    1















    Worked on Elastic Search 6.4.2. I want to use match_pharseto get the retrieve the results from my index. In the same way I need to apply the filter for that. Any solution for this. I tried the below query



    {
    "query": {
    "bool": {
    "should":
    {
    "match_phrase": {
    "title": "bike riding"
    }}

    }
    }}


    But When I using match_pharse I need to pass the fields in order to get the results. I am sharing my mapping and query that I need to be edited. Any help that I can use the match_phrase for a query.



    Mapping:



    {
    "mapping": {
    "doc": {
    "properties": {
    "content": {
    "type": "text",
    "store": true,
    "analyzer": "my_analyzer"
    },
    "description": {
    "type": "text",
    "fields": {
    "keyword": {
    "type": "keyword",
    "ignore_above": 256
    }
    }
    },
    "domain": {
    "type": "text",
    "fields": {
    "keyword": {
    "type": "keyword",
    "ignore_above": 256
    }
    }
    },
    "host": {
    "type": "keyword",
    "store": true
    },
    "keywords": {
    "type": "text",
    "fields": {
    "keyword": {
    "type": "keyword",
    "ignore_above": 256
    }
    }
    },
    "seed": {
    "type": "keyword",
    "store": true
    },
    "title": {
    "type": "text",
    "store": true,
    "analyzer": "my_analyzer"
    },
    "url": {
    "type": "text",
    "store": true
    }
    }
    }
    }
    }`


    Query:
    How can I add match_phrase to the below one



    {
    "query": {
    "bool" : {
    "must" : {
    "query_string" : {
    "query" : "bike riding"
    }
    },
    "filter" : {
    "term" : { "seed" : "sports" }
    }
    }
    }
    }









    share|improve this question

























      1












      1








      1








      Worked on Elastic Search 6.4.2. I want to use match_pharseto get the retrieve the results from my index. In the same way I need to apply the filter for that. Any solution for this. I tried the below query



      {
      "query": {
      "bool": {
      "should":
      {
      "match_phrase": {
      "title": "bike riding"
      }}

      }
      }}


      But When I using match_pharse I need to pass the fields in order to get the results. I am sharing my mapping and query that I need to be edited. Any help that I can use the match_phrase for a query.



      Mapping:



      {
      "mapping": {
      "doc": {
      "properties": {
      "content": {
      "type": "text",
      "store": true,
      "analyzer": "my_analyzer"
      },
      "description": {
      "type": "text",
      "fields": {
      "keyword": {
      "type": "keyword",
      "ignore_above": 256
      }
      }
      },
      "domain": {
      "type": "text",
      "fields": {
      "keyword": {
      "type": "keyword",
      "ignore_above": 256
      }
      }
      },
      "host": {
      "type": "keyword",
      "store": true
      },
      "keywords": {
      "type": "text",
      "fields": {
      "keyword": {
      "type": "keyword",
      "ignore_above": 256
      }
      }
      },
      "seed": {
      "type": "keyword",
      "store": true
      },
      "title": {
      "type": "text",
      "store": true,
      "analyzer": "my_analyzer"
      },
      "url": {
      "type": "text",
      "store": true
      }
      }
      }
      }
      }`


      Query:
      How can I add match_phrase to the below one



      {
      "query": {
      "bool" : {
      "must" : {
      "query_string" : {
      "query" : "bike riding"
      }
      },
      "filter" : {
      "term" : { "seed" : "sports" }
      }
      }
      }
      }









      share|improve this question














      Worked on Elastic Search 6.4.2. I want to use match_pharseto get the retrieve the results from my index. In the same way I need to apply the filter for that. Any solution for this. I tried the below query



      {
      "query": {
      "bool": {
      "should":
      {
      "match_phrase": {
      "title": "bike riding"
      }}

      }
      }}


      But When I using match_pharse I need to pass the fields in order to get the results. I am sharing my mapping and query that I need to be edited. Any help that I can use the match_phrase for a query.



      Mapping:



      {
      "mapping": {
      "doc": {
      "properties": {
      "content": {
      "type": "text",
      "store": true,
      "analyzer": "my_analyzer"
      },
      "description": {
      "type": "text",
      "fields": {
      "keyword": {
      "type": "keyword",
      "ignore_above": 256
      }
      }
      },
      "domain": {
      "type": "text",
      "fields": {
      "keyword": {
      "type": "keyword",
      "ignore_above": 256
      }
      }
      },
      "host": {
      "type": "keyword",
      "store": true
      },
      "keywords": {
      "type": "text",
      "fields": {
      "keyword": {
      "type": "keyword",
      "ignore_above": 256
      }
      }
      },
      "seed": {
      "type": "keyword",
      "store": true
      },
      "title": {
      "type": "text",
      "store": true,
      "analyzer": "my_analyzer"
      },
      "url": {
      "type": "text",
      "store": true
      }
      }
      }
      }
      }`


      Query:
      How can I add match_phrase to the below one



      {
      "query": {
      "bool" : {
      "must" : {
      "query_string" : {
      "query" : "bike riding"
      }
      },
      "filter" : {
      "term" : { "seed" : "sports" }
      }
      }
      }
      }






      elasticsearch






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 12 '18 at 17:34









      an__snatcheran__snatcher

      588




      588
























          1 Answer
          1






          active

          oldest

          votes


















          1














          Below query is what you would be looking for.



          Notice how I've added quotes around ""bike riding""



          POST <your_index_name>/_search
          {
          "query": {
          "bool" : {
          "must" : {
          "query_string" : {
          "query" : ""bike riding""
          }
          },
          "filter" : {
          "term" : { "seed": "sports" }
          }
          }
          }

          }


          Let me know if it helps!






          share|improve this answer


























          • Hi @Kamal, I tried your query Its gave null values and in filter I removed .keyword for the field name that works exactly as I expected.

            – an__snatcher
            Nov 12 '18 at 19:05











          • Yup yup, sorry about that :) Nevertheless, I'm glad it worked once you removed .keyword.

            – Kamal
            Nov 12 '18 at 19:08











          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53267300%2fapplying-match-phrase-and-filter%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          1














          Below query is what you would be looking for.



          Notice how I've added quotes around ""bike riding""



          POST <your_index_name>/_search
          {
          "query": {
          "bool" : {
          "must" : {
          "query_string" : {
          "query" : ""bike riding""
          }
          },
          "filter" : {
          "term" : { "seed": "sports" }
          }
          }
          }

          }


          Let me know if it helps!






          share|improve this answer


























          • Hi @Kamal, I tried your query Its gave null values and in filter I removed .keyword for the field name that works exactly as I expected.

            – an__snatcher
            Nov 12 '18 at 19:05











          • Yup yup, sorry about that :) Nevertheless, I'm glad it worked once you removed .keyword.

            – Kamal
            Nov 12 '18 at 19:08
















          1














          Below query is what you would be looking for.



          Notice how I've added quotes around ""bike riding""



          POST <your_index_name>/_search
          {
          "query": {
          "bool" : {
          "must" : {
          "query_string" : {
          "query" : ""bike riding""
          }
          },
          "filter" : {
          "term" : { "seed": "sports" }
          }
          }
          }

          }


          Let me know if it helps!






          share|improve this answer


























          • Hi @Kamal, I tried your query Its gave null values and in filter I removed .keyword for the field name that works exactly as I expected.

            – an__snatcher
            Nov 12 '18 at 19:05











          • Yup yup, sorry about that :) Nevertheless, I'm glad it worked once you removed .keyword.

            – Kamal
            Nov 12 '18 at 19:08














          1












          1








          1







          Below query is what you would be looking for.



          Notice how I've added quotes around ""bike riding""



          POST <your_index_name>/_search
          {
          "query": {
          "bool" : {
          "must" : {
          "query_string" : {
          "query" : ""bike riding""
          }
          },
          "filter" : {
          "term" : { "seed": "sports" }
          }
          }
          }

          }


          Let me know if it helps!






          share|improve this answer















          Below query is what you would be looking for.



          Notice how I've added quotes around ""bike riding""



          POST <your_index_name>/_search
          {
          "query": {
          "bool" : {
          "must" : {
          "query_string" : {
          "query" : ""bike riding""
          }
          },
          "filter" : {
          "term" : { "seed": "sports" }
          }
          }
          }

          }


          Let me know if it helps!







          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Nov 12 '18 at 19:04









          an__snatcher

          588




          588










          answered Nov 12 '18 at 18:34









          KamalKamal

          1,6511820




          1,6511820













          • Hi @Kamal, I tried your query Its gave null values and in filter I removed .keyword for the field name that works exactly as I expected.

            – an__snatcher
            Nov 12 '18 at 19:05











          • Yup yup, sorry about that :) Nevertheless, I'm glad it worked once you removed .keyword.

            – Kamal
            Nov 12 '18 at 19:08



















          • Hi @Kamal, I tried your query Its gave null values and in filter I removed .keyword for the field name that works exactly as I expected.

            – an__snatcher
            Nov 12 '18 at 19:05











          • Yup yup, sorry about that :) Nevertheless, I'm glad it worked once you removed .keyword.

            – Kamal
            Nov 12 '18 at 19:08

















          Hi @Kamal, I tried your query Its gave null values and in filter I removed .keyword for the field name that works exactly as I expected.

          – an__snatcher
          Nov 12 '18 at 19:05





          Hi @Kamal, I tried your query Its gave null values and in filter I removed .keyword for the field name that works exactly as I expected.

          – an__snatcher
          Nov 12 '18 at 19:05













          Yup yup, sorry about that :) Nevertheless, I'm glad it worked once you removed .keyword.

          – Kamal
          Nov 12 '18 at 19:08





          Yup yup, sorry about that :) Nevertheless, I'm glad it worked once you removed .keyword.

          – Kamal
          Nov 12 '18 at 19:08


















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53267300%2fapplying-match-phrase-and-filter%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown